Skip to content

Commit

Permalink
use hash as suffix
Browse files Browse the repository at this point in the history
Signed-off-by: huabing zhao <zhaohuabing@gmail.com>
  • Loading branch information
zhaohuabing committed Feb 21, 2024
1 parent eeea5c7 commit 6bc9aec
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion internal/gatewayapi/securitypolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/json"
"errors"
"fmt"
"hash/fnv"
"net/http"
"net/netip"
"net/url"
Expand Down Expand Up @@ -494,6 +495,17 @@ func (t *Translator) buildOIDC(
logoutPath = *oidc.LogoutPath
}

nsName := types.NamespacedName{
Namespace: policy.GetNamespace(),
Name: policy.GetName(),
}
h := fnv.New32a()
_, err = h.Write([]byte(nsName.String()))
if err != nil {
return nil, fmt.Errorf("error generating oauth cookie suffix: %w", err)
}
suffix := strconv.Itoa(int(h.Sum32()))

return &ir.OIDC{
Provider: *provider,
ClientID: oidc.ClientID,
Expand All @@ -502,7 +514,7 @@ func (t *Translator) buildOIDC(
RedirectURL: redirectURL,
RedirectPath: redirectPath,
LogoutPath: logoutPath,
CookieSuffix: fmt.Sprintf("%s-%s", policy.Namespace, policy.Name),
CookieSuffix: suffix,
}, nil
}

Expand Down

0 comments on commit 6bc9aec

Please sign in to comment.