Skip to content

Improve testing for authorization to prevent regressions in topic operations related to subscriptions #19183

Open

Description

@michaeljmarshall

Search before asking

  • I searched in the issues and found nothing similar.

Motivation

In PR #19176, I fixed a minor regression in our authorization code base related to topic operations. We should have better tests or possibly a better design to make sure we catch these regressions before they are merged.

The tests should also cover cases seen in #17123 and in #19184

Solution

Improve tests or improve the framework.

Alternatives

No response

Anything else?

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Activity

  1. added
    type/enhancement
    on Jan 11, 2023
  2. michaeljmarshall commented on Jan 25, 2023

    @michaeljmarshall
    MemberAuthor

    One comment on a potential design is to add something like the following to the TopicOperation enum:

        static public boolean subscriptionNameRequiredForAuthorization(TopicOperation op) {
            switch (op) {
                case CONSUME:
                case RESET_CURSOR:
                case SKIP:
                case SUBSCRIBE:
                case UNSUBSCRIBE:
                    return true;
                default:
                    return false;
            }
        }
        public CompletableFuture<Boolean> allowTopicOperationAsync(TopicName topicName,
                                                                   TopicOperation operation,
                                                                   String role,
                                                                   AuthenticationDataSource authData) {
            if (log.isDebugEnabled()) {
                log.debug("Check if role {} is allowed to execute topic operation {} on topic {}",
                        role, operation, topicName);
            }
            if (!this.conf.isAuthorizationEnabled()) {
                return CompletableFuture.completedFuture(true);
            }
    
            // This check prevents regressions... but it'd run everywhere, how do we use this?
            if (TopicOperation.subscriptionNameRequiredForAuthorization(operation) && authData.hasSubscription()) {
    
            }

    The downside is that it would need to get evaluated on every call to authorize. This could help third party plugins. However, I think the ideal solution catches issues with tests and not with verification in production runtime.

  3. github-actions commented on Feb 25, 2023

    @github-actions

    The issue had no activity for 30 days, mark with Stale label.

  4. michaeljmarshall commented on Mar 1, 2023

    @michaeljmarshall
    MemberAuthor

    Another option is to use assert in the case where we ought to have a subscription. That might not be the right solution though.

  5. github-actions commented on Apr 2, 2023

    @github-actions

    The issue had no activity for 30 days, mark with Stale label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Stalearea/authztype/enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions