8000 feat: support proxy forward headers authentication by pudymody · Pull Request #1105 · go-shiori/shiori · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: support proxy forward headers authentication #1105

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

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

pudymody
Copy link
Contributor
@pudymody pudymody commented May 24, 2025

Hi, i started using Authelia for my SSO and Shiori is one of the apps i use that currently doesnt support neither proxy forwarding headers or OIDC.

This is my attempt at the first as its easier to implement.
There is #860 but it seems dead and outdated.

The default settings are tailored to my use case and should be enough for almost everyone, but open to different ones as this is a new world to me.

I've been testing it locally for now and everything seems to be working

Copy link
codecov bot commented May 24, 2025

Codecov Report

Attention: Patch coverage is 37.97468% with 98 lines in your changes missing coverage. Please review.

Project coverage is 50.73%. Comparing base (6fbaecb) to head (bdff2f9).
Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
internal/webserver/handler.go 0.00% 60 Missing ⚠️
internal/http/middleware/auth_sso_proxy.go 78.78% 10 Missing and 4 partials ⚠️
internal/webserver/server.go 0.00% 9 Missing ⚠️
internal/domains/accounts.go 57.14% 4 Missing and 2 partials ⚠️
internal/config/config.go 0.00% 3 Missing ⚠️
internal/http/middleware/auth.go 0.00% 2 Missing and 1 partial ⚠️
internal/http/server.go 0.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1105      +/-   ##
==========================================
+ Coverage   50.08%   50.73%   +0.64%     
==========================================
  Files          74       75       +1     
  Lines        7389     7532     +143     
==========================================
+ Hits         3701     3821     +120     
- Misses       3366     3371       +5     
- Partials      322      340      +18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

ip, _, err := net.SplitHostPort(remoteAddr)
if err != nil {
var addrErr *net.AddrError
if errors.As(err, &addrErr) && addrErr.Err == "missing port in address" {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While testing locally this always came as ip:port, as the documentation says https://pkg.go.dev/net/http#Request

But the last run on pipelines was a clear ip, i added this just in case 🤷🏻‍♂️

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you manage to reproduce this? (So we can add a test case)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldnt reproduce it, but i added a test with both cases

this.loadAccount();
this.loadSetting();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This swap and the following remove of check is because now we can have a valid session without a token or a previous login, and we need to have the account information already defined to prevent an exception

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's dogfood this a bit in an RC before moving it forward with it. It should work in all cases from the looks of it, but I'd like to be sure.

@fmartingr fmartingr changed the title Add Auth Forward method feat: support proxy forward headers authentication Jun 19, 2025
Copy link
Member
@fmartingr fmartingr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @pudymody, thanks a lot for the implementation! Everything is looking good, but I've pointed some things that I'd like in a different way. Check my comments and let me know if you agree. Thanks!

@@ -65,6 +65,10 @@ type HttpConfig struct {
IDLETimeout time.Duration `env:"HTTP_IDLE_TIMEOUT,default=10s"`
DisableKeepAlive bool `env:"HTTP_DISABLE_KEEP_ALIVE,default=true"`
DisablePreParseMultipartForm bool `env:"HTTP_DISABLE_PARSE_MULTIPART_FORM,default=true"`

SSOEnabled bool `env:"SSO_ENABLED,default=false"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we rename this settings to SSOProxyAuth...? In case we ever support more than one SSO auth method in the future.


SSOEnabled bool `env:"SSO_ENABLED,default=false"`
SSOHeaderName string `env:"SSO_HEADER_NAME,default=Remote-User"`
SSOTrustedProxy []string `env:"SSO_TRUSTED_PROXY,default=10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, fc00::/7"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SSOTrustedProxy []string `env:"SSO_TRUSTED_PROXY,default=10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, fc00::/7"`
SSOTrustedProxies []string `env:"SSO_TRUSTED_PROXY,default=10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, fc00::/7"`

}

func NewAuthMiddleware(deps model.Dependencies) *AuthMiddleware {
return &AuthMiddleware{deps: deps}
plainIPs := deps.Config().Http.SSOTrustedProxy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move the SSO logic to a new middleware? That way we would only inject it if needed (SSOEnabled == true)

Having the logic split would prove useful and is better for long term maintenance. You could even put it in a different file (auth_sso_proxy.go?)

ip, _, err := net.SplitHostPort(remoteAddr)
if err != nil {
var addrErr *net.AddrError
if errors.As(err, &addrErr) && addrErr.Err == "missing port in address" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you manage to reproduce this? (So we can add a test case)

@@ -46,6 +70,57 @@ func (m *AuthMiddleware) OnRequest(deps model.Dependencies, c model.WebContext)
return nil
}

func (m *AuthMiddleware) ssoAccount(deps model.Dependencies, c model.WebContext) *model.AccountDTO {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use getSSOAccount(...) (*model.AccountDTO, error) instead of just logging internally, so we can log all the errors directly in the parent function. What do you think?

this.loadAccount();
this.loadSetting();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's dogfood this a bit in an RC before moving it forward with it. It should work in all cases from the looks of it, but I'd like to be sure.

@pudymody
Copy link
Contributor Author

I think i've addressed all the comments. They were nice suggestions.

Otherwise let me know and i would do what i can.

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

Successfully merging this pull request may close these issues.

2 participants
0