mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-03 08:50:42 +02:00
Add new jwt issuer format route option (#5338)
This commit is contained in:
parent
9e9ed8853f
commit
a42e286637
5 changed files with 831 additions and 680 deletions
|
@ -32,7 +32,18 @@ type HeadersRequest struct {
|
|||
// NewHeadersRequestFromPolicy creates a new HeadersRequest from a policy.
|
||||
func NewHeadersRequestFromPolicy(policy *config.Policy, http RequestHTTP) (*HeadersRequest, error) {
|
||||
input := new(HeadersRequest)
|
||||
input.Issuer = http.Hostname
|
||||
var issuerFormat string
|
||||
if policy != nil {
|
||||
issuerFormat = policy.JWTIssuerFormat
|
||||
}
|
||||
switch issuerFormat {
|
||||
case "", "hostOnly":
|
||||
input.Issuer = http.Hostname
|
||||
case "uri":
|
||||
input.Issuer = fmt.Sprintf("https://%s/", http.Hostname)
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid issuer format: %q", policy.JWTIssuerFormat)
|
||||
}
|
||||
if policy != nil {
|
||||
input.EnableGoogleCloudServerlessAuthentication = policy.EnableGoogleCloudServerlessAuthentication
|
||||
input.EnableRoutingKey = policy.EnvoyOpts.GetLbPolicy() == envoy_config_cluster_v3.Cluster_RING_HASH ||
|
||||
|
|
|
@ -53,6 +53,48 @@ func TestNewHeadersRequestFromPolicy(t *testing.T) {
|
|||
}, req)
|
||||
}
|
||||
|
||||
func TestNewHeadersRequestFromPolicy_IssuerFormat(t *testing.T) {
|
||||
policy := &config.Policy{
|
||||
EnableGoogleCloudServerlessAuthentication: true,
|
||||
From: "https://*.example.com",
|
||||
To: config.WeightedURLs{
|
||||
{
|
||||
URL: *mustParseURL("http://to.example.com"),
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tc := range []struct {
|
||||
format string
|
||||
expected string
|
||||
err string
|
||||
}{
|
||||
{format: "", expected: "from.example.com"},
|
||||
{format: "hostOnly", expected: "from.example.com"},
|
||||
{format: "uri", expected: "https://from.example.com/"},
|
||||
{format: "foo", err: `invalid issuer format: "foo"`},
|
||||
} {
|
||||
policy.JWTIssuerFormat = tc.format
|
||||
req, err := NewHeadersRequestFromPolicy(policy, RequestHTTP{
|
||||
Hostname: "from.example.com",
|
||||
ClientCertificate: ClientCertificateInfo{
|
||||
Leaf: "--- FAKE CERTIFICATE ---",
|
||||
},
|
||||
})
|
||||
if tc.err != "" {
|
||||
assert.ErrorContains(t, err, tc.err)
|
||||
} else {
|
||||
assert.Equal(t, &HeadersRequest{
|
||||
EnableGoogleCloudServerlessAuthentication: true,
|
||||
Issuer: tc.expected,
|
||||
ToAudience: "https://to.example.com",
|
||||
ClientCertificate: ClientCertificateInfo{
|
||||
Leaf: "--- FAKE CERTIFICATE ---",
|
||||
},
|
||||
}, req)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewHeadersRequestFromPolicy_nil(t *testing.T) {
|
||||
req, _ := NewHeadersRequestFromPolicy(nil, RequestHTTP{Hostname: "from.example.com"})
|
||||
assert.Equal(t, &HeadersRequest{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue