Skip to content

Commit

Permalink
authorize: populate issuer even when policy is nil (#4213)
Browse files Browse the repository at this point in the history
authorize: populate issuer even when policy is nil (#4211)

Co-authored-by: Kenneth Jenkins <51246568+kenjenkins@users.noreply.github.com>
  • Loading branch information
backport-actions-token[bot] and kenjenkins committed May 31, 2023
1 parent ab115b6 commit 4a14cab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion authorize/evaluator/headers_evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ type HeadersRequest struct {
// NewHeadersRequestFromPolicy creates a new HeadersRequest from a policy.
func NewHeadersRequestFromPolicy(policy *config.Policy, hostname string) *HeadersRequest {
input := new(HeadersRequest)
input.Issuer = hostname
if policy != nil {
input.EnableGoogleCloudServerlessAuthentication = policy.EnableGoogleCloudServerlessAuthentication
input.EnableRoutingKey = policy.EnvoyOpts.GetLbPolicy() == envoy_config_cluster_v3.Cluster_RING_HASH ||
policy.EnvoyOpts.GetLbPolicy() == envoy_config_cluster_v3.Cluster_MAGLEV
input.Issuer = hostname
input.KubernetesServiceAccountToken = policy.KubernetesServiceAccountToken
for _, wu := range policy.To {
input.ToAudience = "https://" + wu.URL.Hostname()
Expand Down
7 changes: 7 additions & 0 deletions authorize/evaluator/headers_evaluator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ func TestNewHeadersRequestFromPolicy(t *testing.T) {
}, req)
}

func TestNewHeadersRequestFromPolicy_nil(t *testing.T) {
req := NewHeadersRequestFromPolicy(nil, "from.example.com")
assert.Equal(t, &HeadersRequest{
Issuer: "from.example.com",
}, req)
}

func TestHeadersEvaluator(t *testing.T) {
type A = []interface{}
type M = map[string]interface{}
Expand Down

0 comments on commit 4a14cab

Please sign in to comment.