Skip to content

Commit cfa1d6f

Browse files
Merge pull request #60 from andrewheberle/crewjam
Bump version and no longer user rancher version
2 parents 530159c + 1ec6180 commit cfa1d6f

File tree

8 files changed

+46
-377
lines changed

8 files changed

+46
-377
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This service combines some basic functionality of [Authelia](https://www.autheli
99
The process for login is:
1010

1111
1. A reverse proxy, such as HAProxy, gets a HTTP request from a user
12-
2. This proxy performs a process to verify the authentiction of the user via a HTTP sub-requet to `/api/authz/forward-auth`
12+
2. This proxy verifies the authentication of the user via a HTTP sub-requet to `/api/authz/forward-auth`
1313
3. If the user is already authenticated the `/api/authz/forward-auth` returns a `HTTP 200 OK` response along with HTTP headers the proxy may use to identify the user
1414
4. If no valid session is available, a redirect is returned to the proxy which should be returned to the user, which will start the SAML login process
1515

@@ -46,6 +46,7 @@ AUTH_IDP_METADATA=https://idp.example.net/metadata \
4646
--listen string Listen address (default "127.0.0.1:9091")
4747
--sp-cert string Service Provider Certificate
4848
--sp-claim-mapping stringToString Mapping of claims to headers (default [remote-user=urn:oasis:names:tc:SAML:attribute:subject-id,remote-email=mail,remote-name=displayName,remote-groups=role])
49+
--sp-cookie Cookie Name set by Service Provider (default "token")
4950
--sp-key string Service Provider Key
5051
--sp-url string Service Provider URL (default "http://localhost:9091")
5152
```
@@ -60,10 +61,16 @@ For this reason, the token only contains minimal data with the rest contained se
6061

6162
By default this store is a basic in-memory store, which means it cannot be shared among multiple instances of this service and also will be lost on restart. The loss of this data on restart is not particularly problematic as the only result will be that the SP will not be able to validate the user is signed in and force the login flow to the IdP.
6263

64+
If using muliple nodes however, using the in-memory store will cause unexpected re-authentiations if requests are handled by different instances.
65+
6366
When using multiple instances, it is possible to use a PostgreSQL database to store this content.
6467

6568
### Using the same database for multiple deployments
6669

6770
All instances of the same Service Provider should share the same configuration options, including the database store, however if seperate service providers are configured using the same database there is the chance incorrect claims may be returned.
6871

6972
To allow sharing of the same database between seperate Service Providers, the `db-prefix` option will ensure this data is stored in seperate tables.
73+
74+
### Cookie Name
75+
76+
The login "token" is stored as a JWT in a cookie named "token" by default. It is important to ensure that seperate SP's use distinct cookie names to ensure JWT's are correctly validated and not overwritten.

docs/architecture.svg

Lines changed: 4 additions & 348 deletions
Loading

go.mod

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ go 1.24.0
44

55
toolchain go1.24.2
66

7-
replace github.com/crewjam/saml v0.4.14 => github.com/rancher/saml v0.4.14-rancher3
8-
97
require (
108
github.com/andrewheberle/simplecommand v0.3.0
119
github.com/bep/simplecobra v0.6.0
1210
github.com/cloudflare/certinel v0.4.1
13-
github.com/crewjam/saml v0.4.14
11+
github.com/crewjam/saml v0.5.1
1412
github.com/golang-jwt/jwt/v4 v4.5.2
1513
github.com/jackc/pgx/v5 v5.6.0
1614
github.com/karlseguin/ccache/v3 v3.0.6
@@ -20,8 +18,7 @@ require (
2018

2119
require (
2220
github.com/andrewheberle/simpleviper v1.1.1 // indirect
23-
github.com/beevik/etree v1.2.0 // indirect
24-
github.com/crewjam/httperr v0.2.0 // indirect
21+
github.com/beevik/etree v1.5.0 // indirect
2522
github.com/fsnotify/fsnotify v1.8.0 // indirect
2623
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
2724
github.com/inconshreveable/mousetrap v1.1.0 // indirect
@@ -31,7 +28,6 @@ require (
3128
github.com/jonboulle/clockwork v0.4.0 // indirect
3229
github.com/mattermost/xml-roundtrip-validator v0.1.0 // indirect
3330
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
34-
github.com/pkg/errors v0.9.1 // indirect
3531
github.com/sagikazarmark/locafero v0.7.0 // indirect
3632
github.com/sourcegraph/conc v0.3.0 // indirect
3733
github.com/spf13/afero v1.12.0 // indirect
@@ -42,9 +38,9 @@ require (
4238
github.com/subosito/gotenv v1.6.0 // indirect
4339
go.uber.org/atomic v1.9.0 // indirect
4440
go.uber.org/multierr v1.9.0 // indirect
45-
golang.org/x/crypto v0.32.0 // indirect
46-
golang.org/x/sync v0.10.0 // indirect
47-
golang.org/x/sys v0.29.0 // indirect
48-
golang.org/x/text v0.21.0 // indirect
41+
golang.org/x/crypto v0.33.0 // indirect
42+
golang.org/x/sync v0.11.0 // indirect
43+
golang.org/x/sys v0.30.0 // indirect
44+
golang.org/x/text v0.22.0 // indirect
4945
gopkg.in/yaml.v3 v3.0.1 // indirect
5046
)

go.sum

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ github.com/andrewheberle/simplecommand v0.3.0/go.mod h1:D9L/jnIotmn3rxyAYIKAAd9r
33
github.com/andrewheberle/simpleviper v1.1.1 h1:9cgJDjcQZoQD1OrgjdMgWP4oFVlFGaHXzxVOsJz0abE=
44
github.com/andrewheberle/simpleviper v1.1.1/go.mod h1:xMIWZmEaiCzd86Pq1YNb0PQ/4Fz5thKInTscmfUvUmw=
55
github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A=
6-
github.com/beevik/etree v1.2.0 h1:l7WETslUG/T+xOPs47dtd6jov2Ii/8/OjCldk5fYfQw=
7-
github.com/beevik/etree v1.2.0/go.mod h1:aiPf89g/1k3AShMVAzriilpcE4R/Vuor90y83zVZWFc=
6+
github.com/beevik/etree v1.5.0 h1:iaQZFSDS+3kYZiGoc9uKeOkUY3nYMXOKLl6KIJxiJWs=
7+
github.com/beevik/etree v1.5.0/go.mod h1:gPNJNaBGVZ9AwsidazFZyygnd+0pAU38N4D+WemwKNs=
88
github.com/bep/simplecobra v0.6.0 h1:PpY/0PvYp6jt4OC/9SGoNPi6HzvpYzu8IPogVV6Xk90=
99
github.com/bep/simplecobra v0.6.0/go.mod h1:q0ecBAefJZYpzgkbPbQ901hzA98g3ZvCZWZRhzNtB5o=
1010
github.com/cloudflare/certinel v0.4.1 h1:b0nGqKxEjCe6aS3SoZf0HwjkzfCCAqGzZj8iB9ZJGW0=
1111
github.com/cloudflare/certinel v0.4.1/go.mod h1:hcx0SA3fmeMzo6egeOzN/29/xfA4+bhZttHvR20a4YA=
1212
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
1313
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
14-
github.com/crewjam/httperr v0.2.0 h1:b2BfXR8U3AlIHwNeFFvZ+BV1LFvKLlzMjzaTnZMybNo=
15-
github.com/crewjam/httperr v0.2.0/go.mod h1:Jlz+Sg/XqBQhyMjdDiC+GNNRzZTD7x39Gu3pglZ5oH4=
14+
github.com/crewjam/saml v0.5.1 h1:g+mfp0CrLuLRZCK793PgJcZeg5dS/0CDwoeAX2zcwNI=
15+
github.com/crewjam/saml v0.5.1/go.mod h1:r0fDkmFe5URDgPrmtH0IYokva6fac3AUdstiPhyEolQ=
1616
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1717
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1818
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -57,13 +57,10 @@ github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DV
5757
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
5858
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
5959
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
60-
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
6160
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
6261
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
6362
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
6463
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
65-
github.com/rancher/saml v0.4.14-rancher3 h1:2NN6cPqm9FJeiT25x8+gLHWGdulsEak33cHRkGaJ5v0=
66-
github.com/rancher/saml v0.4.14-rancher3/go.mod h1:S4+611dxnKt8z/ulbvaJzcgSHsuhjVc1QHNTcr1R7Fw=
6764
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
6865
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
6966
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
@@ -88,7 +85,6 @@ github.com/spf13/viper v1.20.1 h1:ZMi+z/lvLyPSCoNtFCpqjy0S4kPbirhpTMwl8BkW9X4=
8885
github.com/spf13/viper v1.20.1/go.mod h1:P9Mdzt1zoHIG8m2eZQinpiBjo6kCmZSKBClNNqjJvu4=
8986
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
9087
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
91-
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
9288
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
9389
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
9490
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
@@ -99,20 +95,19 @@ go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
9995
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
10096
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
10197
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
102-
golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
103-
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
104-
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
105-
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
106-
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
107-
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
108-
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
109-
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
98+
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
99+
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
100+
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
101+
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
102+
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
103+
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
104+
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
105+
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
110106
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
111107
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
112108
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
113109
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
114110
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
115-
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
116111
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
117112
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
118113
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

internal/pkg/cmd/cmd.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type rootCommand struct {
2828
debug bool
2929

3030
// sp flags
31+
spCookie string
3132
spCert string
3233
spKey string
3334
spUrl string
@@ -61,6 +62,7 @@ func (c *rootCommand) Init(cd *simplecobra.Commandeer) error {
6162
cmd.Flags().BoolVar(&c.debug, "debug", false, "Enable debug logging")
6263

6364
// sp command line flags
65+
cmd.Flags().StringVar(&c.spCookie, "sp-cookie", "token", "Cookie Name set by Service Provider")
6466
cmd.Flags().StringVar(&c.spCert, "sp-cert", "", "Service Provider Certificate")
6567
cmd.Flags().StringVar(&c.spKey, "sp-key", "", "Service Provider Key")
6668
cmd.MarkFlagsRequiredTogether("sp-cert", "sp-key")
@@ -107,6 +109,7 @@ type serviceProvider struct {
107109
ServiceProviderClaimMapping map[string]string `mapstructure:"sp-claim-mapping"`
108110
ServiceProviderCertificate string `mapstructure:"sp-cert"`
109111
ServiceProviderKey string `mapstructure:"sp-key"`
112+
ServiceProviderCookieName string `mapstructure:"sp-cookie"`
110113
IdPMetadata string `mapstructure:"idp-metadata"`
111114
IdPIssuer string `mapstructure:"idp-issuer"`
112115
IdPSSOEndpoint string `mapstructure:"idp-sso-endpoint"`
@@ -127,6 +130,7 @@ func (c *rootCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, args
127130
// use global values as a fallback if some values are not set
128131
spConfig.ServiceProviderCertificate = fallback(spConfig.ServiceProviderCertificate, c.spCert)
129132
spConfig.ServiceProviderKey = fallback(spConfig.ServiceProviderKey, c.spKey)
133+
spConfig.ServiceProviderCookieName = fallback(spConfig.ServiceProviderCookieName, c.spCookie)
130134

131135
// show config in debug mode
132136
c.logger.Debug("setting up service provider",
@@ -146,6 +150,7 @@ func (c *rootCommand) Run(ctx context.Context, cd *simplecobra.Commandeer, args
146150
// set up service provider options
147151
opts := []sp.ServiceProviderOption{
148152
sp.WithClaimMapping(spConfig.ServiceProviderClaimMapping),
153+
sp.WithCookieName(spConfig.ServiceProviderCookieName),
149154
}
150155

151156
// handle metadata
@@ -302,6 +307,7 @@ func (c *rootCommand) serviceProviders() []serviceProvider {
302307
ServiceProviderClaimMapping: c.spClaimMapping,
303308
ServiceProviderCertificate: c.spCert,
304309
ServiceProviderKey: c.spKey,
310+
ServiceProviderCookieName: c.spCookie,
305311
IdPMetadata: c.idpMetadata,
306312
IdPIssuer: c.idpIssuer,
307313
IdPSSOEndpoint: c.idpSSOEndpoint,
@@ -320,6 +326,7 @@ func (c *rootCommand) serviceProviders() []serviceProvider {
320326
ServiceProviderClaimMapping: c.spClaimMapping,
321327
ServiceProviderCertificate: c.spCert,
322328
ServiceProviderKey: c.spKey,
329+
ServiceProviderCookieName: c.spCookie,
323330
IdPMetadata: c.idpMetadata,
324331
IdPIssuer: c.idpIssuer,
325332
IdPSSOEndpoint: c.idpSSOEndpoint,

pkg/sp/options.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ func WithMetadataRefreshInterval(d time.Duration) ServiceProviderOption {
6767
}
6868
}
6969

70+
func WithCookieName(name string) ServiceProviderOption {
71+
return func(s *ServiceProvider) {
72+
s.cookieName = name
73+
}
74+
}
75+
7076
func WithName(name string) ServiceProviderOption {
7177
return func(s *ServiceProvider) {
7278
s.name = name

pkg/sp/sp.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type ServiceProvider struct {
2929
store AttributeStore
3030
opts samlsp.Options
3131
name string
32+
cookieName string
3233
onerror func(w http.ResponseWriter, r *http.Request, err error)
3334
}
3435

@@ -77,6 +78,7 @@ func NewServiceProvider(cert, key string, root *url.URL, options ...ServiceProvi
7778
EntityID: root.String(),
7879
Key: keyPair.PrivateKey.(*rsa.PrivateKey),
7980
Certificate: keyPair.Leaf,
81+
CookieName: serviceProvider.cookieName,
8082
IDPMetadata: serviceProvider.idpMetadata,
8183
AllowIDPInitiated: true,
8284
SignRequest: true,

pkg/sp/tracker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
func DefaultRequestTracker(opts samlsp.Options, serviceProvider *saml.ServiceProvider) CookieRequestTracker {
1616
return CookieRequestTracker{
1717
ServiceProvider: serviceProvider,
18-
NamePrefix: "saml_",
18+
NamePrefix: fmt.Sprintf("saml_%s_", opts.CookieName),
1919
Codec: samlsp.DefaultTrackedRequestCodec(opts),
2020
MaxAge: saml.MaxIssueDelay,
2121
RelayStateFunc: opts.RelayStateFunc,

0 commit comments

Comments
 (0)