tchiotludo / akhq

Kafka GUI for Apache Kafka to manage topics, topics data, consumers group, schema registry, connect and more...
https://akhq.io/
Apache License 2.0
3.36k stars 652 forks source link

HashMap topics-filter-regexp key not in kebab case #571

Closed klDen closed 3 years ago

klDen commented 3 years ago

Hello!

I tried defining a new security.groups with the attribute topics-filter-regexp in the application.yml file.

After troubleshooting in the code base of akhq, I found that the conditions are never met since it expects topics-filter-regexp (kebab-case) while the key in the hashmap is topicsFilterRegexp (camel-case).

It seems like keys of nested maps are being converted by io.micronaut.core.naming.NameUtils#dehyphenate .

Should the condition be modified to be of camel-case instead?

Thanks a lot!

Tested on latest dev branch.

image

tchiotludo commented 3 years ago

Seems to be really weird, there is unit test about that and I know people is using it. Maybe you can share your configuration files ?

klDen commented 3 years ago

Here is the config used (modified from src/main/resources/application.yml):

micronaut:
  application:
    name: akhq
  io:
    watch:
      paths: src/main
      restart: false # enabled dev server with env vars MICRONAUT_IO_WATCH_RESTART=true
  server:
    thread-selection: AUTO
  router:
    static-resources:
      react:
        paths: classpath:ui
        mapping: "/ui/**"
      static:
        paths: classpath:static
        mapping: "/static/**"
      swagger:
        paths: classpath:META-INF/swagger
        mapping: "/swagger/**"
  security:
    enabled: false
    authentication: cookie
    endpoints:
      login:
        path: "/login"
      logout:
        path: "/logout"
        get-allowed: true
    token:
      jwt:
        enabled: true
        cookie:
          enabled: true
          cookie-same-site: strict
        signatures:
          secret:
            generator:
              secret: "pleasechangeme!pleasechangeme!pleasechangeme!pleasechangeme!pleasechangeme!pleasechangeme!pleasechangeme!pleasechangeme!pleasechangeme!pleasechangeme!pleasechangeme!pleasechangeme!pleasechangeme!pleasechangeme!pleasechangeme!pleasechangeme!"

    redirect:
      login-success: "${micronaut.server.context-path:}/ui"
      forbidden:
        url: "${micronaut.server.context-path:}/ui/login/forbidden"
      unauthorized:
        url: "${micronaut.server.context-path:}/ui/login/unauthorized"
      login-failure: "${micronaut.server.context-path:}/ui/login/failed"
      logout:  "${micronaut.server.context-path:}/ui"
    intercept-url-map:
      - pattern: "${micronaut.server.context-path:}/ui/**"
        access: "isAnonymous()"
      - pattern: "${micronaut.server.context-path:}/static/**"
        access: "isAnonymous()"
      - pattern: "${micronaut.server.context-path:}/swagger/**"
        access: "isAnonymous()"
    oauth2:
      login-uri: "${micronaut.server.context-path:}/oauth/login{/provider}"
      callback-uri: "${micronaut.server.context-path:}/oauth/callback{/provider}"
  caches:
    kafka-wrapper:
      record-stats: true
      expire-after-write: 0s

jackson:
  serialization:
    writeDatesAsTimestamps: false

endpoints:
  all:
    port: 8081
    enabled: true
    sensitive: false
  health:
    details-visible: ANONYMOUS
  loggers:
    write-sensitive: false

akhq:
  server:
    access-log:
      enabled: true
      name: org.akhq.log.access
      format: "[Date: {}] [Duration: {} ms] [Url: {} {}] [Status: {}] [Ip: {}] [User: {}]"
      filters:
        - "((?!/health).)*"

  clients-defaults:
    consumer:
      properties:
        max.poll.records: 50
        isolation.level: read_committed
        # group.id: Akhq
        enable.auto.commit: "false"
        default.api.timeout.ms: 15000

  pagination:
    page-size: 25
    threads: 16

  topic:
    replication: 1
    retention: 86400000
    partition: 1
    internal-regexps:
      - "^_.*$"
      - "^.*_schemas$"
      - "^.*connect-config$"
      - "^.*connect-offsets$1"
      - "^.*connect-status$"
    stream-regexps:
      - "^.*-changelog$"
      - "^.*-repartition$"
      - "^.*-rekey$"

  topic-data:
    sort: OLDEST
    size: 50
    poll-timeout: 1000

  security:
    default-group: test-roles # <---- modified here from default
    groups:
      admin:
        name: admin
        roles:
        - topic/read
        - topic/insert
        - topic/delete
        - topic/config/update
        - node/read
        - node/config/update
        - topic/data/read
        - topic/data/insert
        - topic/data/delete
        - group/read
        - group/delete
        - group/offsets/update
        - registry/read
        - registry/insert
        - registry/update
        - registry/delete
        - registry/version/delete
        - acls/read
        - connect/read
        - connect/insert
        - connect/update
        - connect/delete
        - connect/state/update
      reader:
        name: reader
        roles:
        - topic/read
        - node/read
        - topic/data/read
        - group/read
        - registry/read
        - acls/read
        - connect/read
      no-roles:
        name: no-roles
        roles: []
      test-roles: # <---- modified here from default
        name: test-roles
        roles:
          - topic/read
          - node/read
        attributes:
          topics-filter-regexp: "^test$"

  connections: # <---- modified here from default
    test-cluster:
      properties:
        bootstrap.servers: "localhost:9092"
klDen commented 3 years ago

About the unit test, is org.akhq.repositories.TopicRepositoryTest#mockApplicationContext the one you were referring to? I tried debugging it as well and it does respect kebab-case while running from the main App doesn't :|

tchiotludo commented 3 years ago

Seems to be right, really strange is was not spotted before... Can you try with dev version please ?

klDen commented 3 years ago

Yup it should work based on your commit! Thanks!