mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-06 02:09:15 +02:00
config: generate cookie secret if not set in all-in-one mode
This commit is contained in:
parent
2c9087f5e7
commit
d6dbf86b2d
2 changed files with 39 additions and 1 deletions
|
@ -985,7 +985,7 @@ func (o *Options) GetSharedKey() ([]byte, error) {
|
||||||
sharedKey = string(bs)
|
sharedKey = string(bs)
|
||||||
}
|
}
|
||||||
// mutual auth between services on the same host can be generated at runtime
|
// mutual auth between services on the same host can be generated at runtime
|
||||||
if IsAll(o.Services) && o.SharedKey == "" && o.DataBrokerStorageType == StorageInMemoryName {
|
if IsAll(o.Services) && sharedKey == "" {
|
||||||
sharedKey = randomSharedKey
|
sharedKey = randomSharedKey
|
||||||
}
|
}
|
||||||
if sharedKey == "" {
|
if sharedKey == "" {
|
||||||
|
@ -1188,6 +1188,14 @@ func (o *Options) GetCookieSecret() ([]byte, error) {
|
||||||
}
|
}
|
||||||
cookieSecret = string(bs)
|
cookieSecret = string(bs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if IsAll(o.Services) && cookieSecret == "" {
|
||||||
|
cookieSecret = randomSharedKey
|
||||||
|
}
|
||||||
|
if cookieSecret == "" {
|
||||||
|
return nil, errors.New("empty cookie secret")
|
||||||
|
}
|
||||||
|
|
||||||
return base64.StdEncoding.DecodeString(cookieSecret)
|
return base64.StdEncoding.DecodeString(cookieSecret)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -776,6 +776,36 @@ func TestOptions_GetSetResponseHeaders(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestOptions_GetSharedKey(t *testing.T) {
|
||||||
|
t.Run("default", func(t *testing.T) {
|
||||||
|
o := NewDefaultOptions()
|
||||||
|
bs, err := o.GetSharedKey()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, randomSharedKey, base64.StdEncoding.EncodeToString(bs))
|
||||||
|
})
|
||||||
|
t.Run("missing", func(t *testing.T) {
|
||||||
|
o := NewDefaultOptions()
|
||||||
|
o.Services = ServiceProxy
|
||||||
|
_, err := o.GetSharedKey()
|
||||||
|
assert.Error(t, err)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOptions_GetCookieSecret(t *testing.T) {
|
||||||
|
t.Run("default", func(t *testing.T) {
|
||||||
|
o := NewDefaultOptions()
|
||||||
|
bs, err := o.GetCookieSecret()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, randomSharedKey, base64.StdEncoding.EncodeToString(bs))
|
||||||
|
})
|
||||||
|
t.Run("missing", func(t *testing.T) {
|
||||||
|
o := NewDefaultOptions()
|
||||||
|
o.Services = ServiceProxy
|
||||||
|
_, err := o.GetCookieSecret()
|
||||||
|
assert.Error(t, err)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func encodeCert(cert *tls.Certificate) []byte {
|
func encodeCert(cert *tls.Certificate) []byte {
|
||||||
return pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: cert.Certificate[0]})
|
return pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: cert.Certificate[0]})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue