mirror of
https://github.com/pomerium/pomerium.git
synced 2025-06-02 19:04:14 +02:00
## Summary Update the `RouteID` to use the `policy.ID` if it is set. This makes it so that updated routes use a stable identifier between updates so if the envoy control plane is updated before the authorize service's internal definitions (or vice-versa) the authorize service will still be able to match the route. The current behavior results in a 404 if envoy passes the old route id. The new behavior will result in inconsistency, but it should be quickly remedied. To help with debugging 4 new fields were added to the authorize check log. The `route-id` and `route-checksum` as the authorize sees it and the `envoy-route-id` and `envoy-route-checksum` as envoy sees it. I also updated the way we send updates to envoy to try and model their recommended approach: > In general, to avoid traffic drop, sequencing of updates should follow a make before break model, wherein: > > - CDS updates (if any) must always be pushed first. > - EDS updates (if any) must arrive after CDS updates for the respective clusters. > - LDS updates must arrive after corresponding CDS/EDS updates. > - RDS updates related to the newly added listeners must arrive after CDS/EDS/LDS updates. > - VHDS updates (if any) related to the newly added RouteConfigurations must arrive after RDS updates. > - Stale CDS clusters and related EDS endpoints (ones no longer being referenced) can then be removed. This should help avoid 404s when configuration is being updated. ## Related issues - [ENG-2386](https://linear.app/pomerium/issue/ENG-2386/large-number-of-routes-leads-to-404s-and-slowness) ## Checklist - [x] reference any related issues - [x] updated unit tests - [x] add appropriate label (`enhancement`, `bug`, `breaking`, `dependencies`, `ci`) - [x] ready for review
108 lines
4.4 KiB
Go
108 lines
4.4 KiB
Go
package authorize
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/rs/zerolog"
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/pomerium/pomerium/authorize/evaluator"
|
|
"github.com/pomerium/pomerium/config"
|
|
"github.com/pomerium/pomerium/internal/log"
|
|
"github.com/pomerium/pomerium/pkg/grpc/session"
|
|
"github.com/pomerium/pomerium/pkg/grpc/user"
|
|
"github.com/pomerium/pomerium/pkg/telemetry/requestid"
|
|
)
|
|
|
|
func Test_populateLogEvent(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
ctx := context.Background()
|
|
ctx = requestid.WithValue(ctx, "REQUEST-ID")
|
|
|
|
req := &evaluator.Request{
|
|
HTTP: evaluator.RequestHTTP{
|
|
Method: "GET",
|
|
Host: "HOST",
|
|
RawPath: "/some/path",
|
|
RawQuery: "a=b",
|
|
Headers: map[string]string{"X-Request-Id": "CHECK-REQUEST-ID"},
|
|
IP: "127.0.0.1",
|
|
},
|
|
EnvoyRouteChecksum: 1234,
|
|
EnvoyRouteID: "ROUTE-ID",
|
|
Policy: &config.Policy{
|
|
ID: "POLICY-ID",
|
|
},
|
|
}
|
|
s := &session.Session{
|
|
Id: "SESSION-ID",
|
|
IdToken: &session.IDToken{
|
|
Raw: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE2OTAzMTU4NjIsImV4cCI6MTcyMTg1MTg2MiwiYXVkIjoid3d3LmV4YW1wbGUuY29tIiwic3ViIjoianJvY2tldEBleGFtcGxlLmNvbSIsIkdpdmVuTmFtZSI6IkpvaG5ueSIsIlN1cm5hbWUiOiJSb2NrZXQiLCJFbWFpbCI6Impyb2NrZXRAZXhhbXBsZS5jb20iLCJSb2xlIjpbIk1hbmFnZXIiLCJQcm9qZWN0IEFkbWluaXN0cmF0b3IiXX0.AAojgaG0fjMFwMCAC6YALHHMFIZEedFSP_vMGhiHhso",
|
|
},
|
|
UserId: "USER-ID",
|
|
}
|
|
sa := &user.ServiceAccount{
|
|
Id: "SERVICE-ACCOUNT-ID",
|
|
UserId: "SERVICE-ACCOUNT-USER-ID",
|
|
}
|
|
u := &user.User{
|
|
Id: "USER-ID",
|
|
Email: "EMAIL",
|
|
}
|
|
impersonateDetails := &impersonateDetails{
|
|
email: "IMPERSONATE-EMAIL",
|
|
sessionID: "IMPERSONATE-SESSION-ID",
|
|
userID: "IMPERSONATE-USER-ID",
|
|
}
|
|
res := &evaluator.Result{
|
|
AdditionalLogFields: map[log.AuthorizeLogField]any{
|
|
log.AuthorizeLogFieldRemovedGroupsCount: 42,
|
|
},
|
|
}
|
|
|
|
for _, tc := range []struct {
|
|
field log.AuthorizeLogField
|
|
s sessionOrServiceAccount
|
|
expect string
|
|
}{
|
|
{log.AuthorizeLogFieldCheckRequestID, s, `{"check-request-id":"CHECK-REQUEST-ID"}`},
|
|
{log.AuthorizeLogFieldEmail, s, `{"email":"EMAIL"}`},
|
|
{log.AuthorizeLogFieldEnvoyRouteChecksum, s, `{"envoy-route-checksum":1234}`},
|
|
{log.AuthorizeLogFieldEnvoyRouteID, s, `{"envoy-route-id":"ROUTE-ID"}`},
|
|
{log.AuthorizeLogFieldHost, s, `{"host":"HOST"}`},
|
|
{log.AuthorizeLogFieldIDToken, s, `{"id-token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE2OTAzMTU4NjIsImV4cCI6MTcyMTg1MTg2MiwiYXVkIjoid3d3LmV4YW1wbGUuY29tIiwic3ViIjoianJvY2tldEBleGFtcGxlLmNvbSIsIkdpdmVuTmFtZSI6IkpvaG5ueSIsIlN1cm5hbWUiOiJSb2NrZXQiLCJFbWFpbCI6Impyb2NrZXRAZXhhbXBsZS5jb20iLCJSb2xlIjpbIk1hbmFnZXIiLCJQcm9qZWN0IEFkbWluaXN0cmF0b3IiXX0.AAojgaG0fjMFwMCAC6YALHHMFIZEedFSP_vMGhiHhso"}`},
|
|
{log.AuthorizeLogFieldIDTokenClaims, s, `{"id-token-claims":{"Email":"jrocket@example.com","GivenName":"Johnny","Role":["Manager","Project Administrator"],"Surname":"Rocket","aud":"www.example.com","exp":1721851862,"iat":1690315862,"iss":"Online JWT Builder","sub":"jrocket@example.com"}}`},
|
|
{log.AuthorizeLogFieldImpersonateEmail, s, `{"impersonate-email":"IMPERSONATE-EMAIL"}`},
|
|
{log.AuthorizeLogFieldImpersonateSessionID, s, `{"impersonate-session-id":"IMPERSONATE-SESSION-ID"}`},
|
|
{log.AuthorizeLogFieldImpersonateUserID, s, `{"impersonate-user-id":"IMPERSONATE-USER-ID"}`},
|
|
{log.AuthorizeLogFieldIP, s, `{"ip":"127.0.0.1"}`},
|
|
{log.AuthorizeLogFieldMethod, s, `{"method":"GET"}`},
|
|
{log.AuthorizeLogFieldPath, s, `{"path":"/some/path"}`},
|
|
{log.AuthorizeLogFieldQuery, s, `{"query":"a=b"}`},
|
|
{log.AuthorizeLogFieldRemovedGroupsCount, s, `{"removed-groups-count":42}`},
|
|
{log.AuthorizeLogFieldRequestID, s, `{"request-id":"REQUEST-ID"}`},
|
|
{log.AuthorizeLogFieldRouteChecksum, s, `{"route-checksum":14294378844626301341}`},
|
|
{log.AuthorizeLogFieldRouteID, s, `{"route-id":"POLICY-ID"}`},
|
|
{log.AuthorizeLogFieldServiceAccountID, sa, `{"service-account-id":"SERVICE-ACCOUNT-ID"}`},
|
|
{log.AuthorizeLogFieldSessionID, s, `{"session-id":"SESSION-ID"}`},
|
|
{log.AuthorizeLogFieldUser, s, `{"user":"USER-ID"}`},
|
|
{log.AuthorizeLogFieldUser, sa, `{"user":"SERVICE-ACCOUNT-USER-ID"}`},
|
|
{log.AuthorizeLogFieldUser, nil, `{"user":""}`},
|
|
} {
|
|
t.Run(string(tc.field), func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
var buf bytes.Buffer
|
|
log := zerolog.New(&buf)
|
|
evt := log.Log()
|
|
evt = populateLogEvent(ctx, tc.field, evt, req, tc.s, u, impersonateDetails, res)
|
|
evt.Send()
|
|
|
|
assert.Equal(t, tc.expect, strings.TrimSpace(buf.String()))
|
|
})
|
|
}
|
|
}
|