Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix signing key template processing dropping allow #3390

Merged
merged 3 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions server/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,10 @@ func processUserPermissionsTemplate(lim jwt.UserPermissionLimits, ujwt *jwt.User
}
return emittedList, nil
}

subAllowWasEmpty := len(lim.Permissions.Sub.Allow) > 0
pubAllowWasEmpty := len(lim.Permissions.Pub.Allow) > 0

var err error
if lim.Permissions.Sub.Allow, err = applyTemplate(lim.Permissions.Sub.Allow, false); err != nil {
return jwt.UserPermissionLimits{}, err
Expand All @@ -523,6 +527,14 @@ func processUserPermissionsTemplate(lim jwt.UserPermissionLimits, ujwt *jwt.User
} else if lim.Permissions.Pub.Deny, err = applyTemplate(lim.Permissions.Pub.Deny, true); err != nil {
return jwt.UserPermissionLimits{}, err
}

// if pub/sub allow where not empty, but are empty post template processing, add in a deny to compensate
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

were instead of where. But more importantly, looks like the code is opposite of the comment. That is, you wrote if they were not empty, but are empty after processing add deny. Then should it not be if !subAllowWasEmpty && .. (notice the "!"). Same for the pub.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong variable name. fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for pointing that out

if subAllowWasEmpty && len(lim.Permissions.Sub.Allow) == 0 {
lim.Permissions.Sub.Deny.Add(">")
}
if pubAllowWasEmpty && len(lim.Permissions.Pub.Allow) == 0 {
lim.Permissions.Pub.Deny.Add(">")
}
return lim, nil
}

Expand Down
4 changes: 3 additions & 1 deletion server/jwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4416,8 +4416,10 @@ func TestJwtTemplates(t *testing.T) {
test(resLim.Pub.Deny, []string{"foo1.acc1", "foo1.acc2", "foo2.acc1", "foo2.acc2"})

require_True(t, len(resLim.Sub.Allow) == 0)
require_True(t, len(resLim.Sub.Deny) == 1)
require_True(t, len(resLim.Sub.Deny) == 2)
require_Contains(t, resLim.Sub.Deny[0], fmt.Sprintf("foo.myname.%s.accname.%s.bar", upub, aPub))
// added in to compensate for sub allow not resolving
require_Contains(t, resLim.Sub.Deny[1], fmt.Sprintf(">"))

lim.Pub.Deny.Add("{{tag(NOT_THERE)}}")
_, err = processUserPermissionsTemplate(lim, uclaim, acc)
Expand Down