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: remove default namespace as a requirement to list namespaces v2 #3716

Merged
merged 3 commits into from
Dec 15, 2024

Conversation

erka
Copy link
Collaborator

@erka erka commented Dec 10, 2024

Ninja has more tricks :(

related #3711

@erka erka requested a review from a team as a code owner December 10, 2024 21:44
Copy link

codecov bot commented Dec 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 64.55%. Comparing base (2e3fd06) to head (e6e0121).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3716   +/-   ##
=======================================
  Coverage   64.55%   64.55%           
=======================================
  Files         170      170           
  Lines       17163    17163           
=======================================
  Hits        11079    11079           
  Misses       5393     5393           
  Partials      691      691           
Flag Coverage Δ
unittests 64.55% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

func WithNoNamespace() func(*Request) {
return func(r *Request) {
r.Namespace = ""
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

im confused about what the difference is between using this and what you did previously by setting WithNamespace("") in the ListNamespaceRequest

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@markphelps It would be nice if you double check it with me. Burned once already...

WithNamespace doesn't allow to set empty string for some reason

func WithNamespace(ns string) func(*Request) {
return func(r *Request) {
if ns != "" {
r.Namespace = ns
}
}
}

As WithNamespace is a public func, I can't remove condition without breaking changes for others. So I've created a new option WithNoNamespace.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we are the only ones who use this function as its only used internally to enforce authz, so I think its fine to remove the check for empty string in the function body

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@markphelps Could you please help me how to move forward? The integration tests has a case where the empty namespace should fallback to default namespace. Should I skip this case for authz integration tests or should I continue with WithNoNamespace option and keep all the integration test cases?

Copy link
Collaborator

Choose a reason for hiding this comment

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

i guess ideally we should continue again with the WithNoNamespace option to keep the integration tests. we should likely add one to make sure that they can list namespaces still if WithNoNamespace is used

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am stuck. Integration tests for authz don't have calls with ListNamespaceRequest as I see. What is going on? Where is my blind spot? Why namespaced viewer could be affected by this change?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@erka I will take a look this evening

Copy link
Collaborator

Choose a reason for hiding this comment

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

so the policy for the IT is coming from here: https://github.com/flipt-io/flipt/blob/main/build/testing/integration.go#L704-L839

default allow = false

allow if {
    input.authentication.metadata["is_bootstrap"] == "true"
}

allow if {
	some rule in has_rules

	permit_string(rule.resource, input.request.resource)
	permit_slice(rule.actions, input.request.action)
	permit_string(rule.namespace, input.request.namespace)
}

allow if {
	some rule in has_rules

	permit_string(rule.resource, input.request.resource)
	permit_slice(rule.actions, input.request.action)
	not rule.namespace
}

has_rules contains rules if {
	some role in data.roles
	role.name == input.authentication.metadata["io.flipt.auth.role"]
	rules := role.rules[_]
}

has_rules contains rules if {
	some role in data.roles
	role.name == input.authentication.metadata["io.flipt.auth.k8s.serviceaccount.name"]
	rules := role.rules[_]
}

and the failing test is here: https://github.com/flipt-io/flipt/blob/main/build/testing/integration/authn/auth.go#L145

so there is some reason that the policy is matching, but that doesn't make sense because we are not passing in a role in the request, so has_rules should be returning the empty set, but it must be returning some rules which makes me think the "" role is being matched somewhere in the policy

I think our rego policy for the authz test is not compatible with the change of allowing no namespace in the request

Copy link
Collaborator Author

@erka erka Dec 13, 2024

Choose a reason for hiding this comment

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

A wild guess... if tests are using rest api and getNamespace with empty namespace, the url probably will be /api/v1/namespaces/ and grpc-gateway could remove the last flash and interpret that as call to list namespaces.

func (x *FliptClient) GetNamespace(ctx context.Context, v *flipt.GetNamespaceRequest, _ ...grpc.CallOption) (*flipt.Namespace, error) {
var body io.Reader
values := url.Values{}
values.Set("reference", v.Reference)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, x.addr+fmt.Sprintf("/api/v1/namespaces/%v", v.Key), body)
if err != nil {
return nil, err
}
req.URL.RawQuery = values.Encode()

erka added 2 commits December 14, 2024 21:42
Ninja has more tricks :(

Signed-off-by: Roman Dmytrenko <[email protected]>
Signed-off-by: Roman Dmytrenko <[email protected]>
@erka
Copy link
Collaborator Author

erka commented Dec 15, 2024

@markphelps any way to get this to main?

Copy link
Collaborator

@markphelps markphelps left a comment

Choose a reason for hiding this comment

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

Thank you for the hard work debugging this! I think we will also update the generated sdk to not allow empty keys but this change should work too

@erka erka merged commit 45252bc into main Dec 15, 2024
41 checks passed
@erka erka deleted the rd/rpc-no-namespace branch December 15, 2024 20:59
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.

2 participants