mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-24 07:39:07 +02:00
[management] Enforce reverse proxy group access before minting and when honouring a session cookie (#7240)
This commit is contained in:
@@ -388,6 +388,7 @@ func (s *Service) ToProtoMapping(operation Operation, authToken string, oidcConf
|
||||
|
||||
if s.Auth.BearerAuth != nil && s.Auth.BearerAuth.Enabled {
|
||||
auth.Oidc = true
|
||||
auth.AllowedGroupIds = append([]string(nil), s.Auth.BearerAuth.DistributionGroups...)
|
||||
}
|
||||
|
||||
for _, h := range s.Auth.HeaderAuths {
|
||||
|
||||
@@ -250,6 +250,44 @@ func TestToProtoMapping_TargetOptions(t *testing.T) {
|
||||
assert.Equal(t, int64(30), opts.RequestTimeout.Seconds)
|
||||
}
|
||||
|
||||
// TestToProtoMapping_AllowedGroupIds covers the list the proxy gates session
|
||||
// cookies on: without it the proxy can only check a cookie's signature, which
|
||||
// makes a token minted for a user outside the groups a bearer credential.
|
||||
func TestToProtoMapping_AllowedGroupIds(t *testing.T) {
|
||||
t.Run("distribution groups reach the proxy", func(t *testing.T) {
|
||||
rp := &Service{
|
||||
ID: "svc-1",
|
||||
AccountID: "acc-1",
|
||||
Domain: "example.com",
|
||||
Auth: AuthConfig{
|
||||
BearerAuth: &BearerAuthConfig{
|
||||
Enabled: true,
|
||||
DistributionGroups: []string{"grp-1", "grp-2"},
|
||||
},
|
||||
},
|
||||
}
|
||||
pm := rp.ToProtoMapping(Create, "token", proxy.OIDCValidationConfig{})
|
||||
|
||||
assert.True(t, pm.GetAuth().GetOidc())
|
||||
assert.Equal(t, []string{"grp-1", "grp-2"}, pm.GetAuth().GetAllowedGroupIds())
|
||||
})
|
||||
|
||||
t.Run("a service open to the account carries no groups", func(t *testing.T) {
|
||||
rp := &Service{
|
||||
ID: "svc-1",
|
||||
AccountID: "acc-1",
|
||||
Domain: "example.com",
|
||||
Auth: AuthConfig{
|
||||
BearerAuth: &BearerAuthConfig{Enabled: true},
|
||||
},
|
||||
}
|
||||
pm := rp.ToProtoMapping(Create, "token", proxy.OIDCValidationConfig{})
|
||||
|
||||
assert.True(t, pm.GetAuth().GetOidc())
|
||||
assert.Empty(t, pm.GetAuth().GetAllowedGroupIds(), "an empty list must not restrict access")
|
||||
})
|
||||
}
|
||||
|
||||
func TestToProtoMapping_NoOptionsWhenDefault(t *testing.T) {
|
||||
rp := &Service{
|
||||
ID: "svc-1",
|
||||
|
||||
Reference in New Issue
Block a user