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

Set namespace on API if not present #3953

Merged
merged 2 commits into from
Feb 16, 2023
Merged

Set namespace on API if not present #3953

merged 2 commits into from
Feb 16, 2023

Conversation

wxing1292
Copy link
Contributor

What changed?

  • Set namespace on API if not present
    • RespondQueryTaskCompletedRequest
    • RespondWorkflowTaskCompletedRequest
    • RespondWorkflowTaskFailedRequest
    • RecordActivityTaskHeartbeatRequest
    • RespondActivityTaskCanceledRequest
    • RespondActivityTaskCompletedRequest
    • RespondActivityTaskFailedRequest

Why?
Better compatibility

How did you test it?
New tests

Potential risks
N/A

Is hotfix candidate?
N/A

@wxing1292 wxing1292 requested a review from a team as a code owner February 14, 2023 02:28
@@ -92,6 +96,10 @@ func (ni *NamespaceValidatorInterceptor) LengthValidationIntercept(
info *grpc.UnaryServerInfo,
handler grpc.UnaryHandler,
) (interface{}, error) {
err := ni.setNamespaceIfNotPresent(ni.namespaceRegistry, req)
if err != nil {
return nil, err
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yiminc @yycptt what if customer modify & put a namespace ID in the task token?

if returning not found error here legit?

Copy link
Member

Choose a reason for hiding this comment

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

Existing behavior will also return not found in this case I think?

Comment on lines 118 to 121
namespaceName := GetNamespace(namespaceRegistry, req)
if namespaceName != "" {
return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

Can we check if req is a NamespaceGetter and if request.GetNamespace() is empty? I feel it's hard to reason about GetNamespace function which hides the error.

Then we also don't need the empty check in setNamespace

@@ -92,6 +96,10 @@ func (ni *NamespaceValidatorInterceptor) LengthValidationIntercept(
info *grpc.UnaryServerInfo,
handler grpc.UnaryHandler,
) (interface{}, error) {
err := ni.setNamespaceIfNotPresent(ni.namespaceRegistry, req)
if err != nil {
return nil, err
Copy link
Member

Choose a reason for hiding this comment

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

Existing behavior will also return not found in this case I think?

req interface{},
) error {
namespaceName := GetNamespace(namespaceRegistry, req)
if namespaceName != "" {
Copy link
Member

Choose a reason for hiding this comment

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

Why not just always set the namespace from the one in the token? Then we can drop all the token stuff from the rest of this file (extractNamespace gets simpler, checkNamespaceMatch goes away, etc.). Also this function and setNamespace gets simpler too

Copy link
Member

Choose a reason for hiding this comment

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

Agree that we can simplify the logic here. My proposal is we can extract namespace from token, then we set it to request if it is empty. If it is not empty we validate it is the same as from token, if they are different then we return error. This will make sure the namespace from request is always the same as it from token, so we can remove all other logic around token validation in this file.

Copy link
Member

Choose a reason for hiding this comment

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

We have to make sure this overwrite happen before authorizer interceptor because auth is done against the namespace set in the request field.

) {
switch request := req.(type) {
case *workflowservice.RespondQueryTaskCompletedRequest:
if request.Namespace == "" {
Copy link
Member

Choose a reason for hiding this comment

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

nit: looks like we no longer need this check.

@yycptt yycptt merged commit a23489b into temporalio:master Feb 16, 2023
@wxing1292 wxing1292 deleted the rename branch February 23, 2023 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants