Skip to content

Commit

Permalink
Merge pull request #732 from jclarysse/jclarysse/fix-500-on-rest-auth…
Browse files Browse the repository at this point in the history
…z-access-denied

REST proxy to return 403 instead of 500 in case of deny by ACL
  • Loading branch information
tvainika authored Oct 6, 2023
2 parents 8a4ff32 + 633773e commit 9a4f91e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions karapace/kafka_rest_apis/consumer_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
from collections import defaultdict, namedtuple
from functools import partial
from http import HTTPStatus
from kafka.errors import GroupAuthorizationFailedError, IllegalStateError, KafkaConfigurationError, KafkaError
from kafka.errors import (
GroupAuthorizationFailedError,
IllegalStateError,
KafkaConfigurationError,
KafkaError,
TopicAuthorizationFailedError,
)
from kafka.structs import TopicPartition
from karapace.config import Config, create_client_ssl_context
from karapace.kafka_rest_apis.error_codes import RESTErrorCodes
Expand Down Expand Up @@ -482,7 +488,7 @@ async def fetch(self, internal_name: Tuple[str, str], content_type: str, formats
timeout_left = max(0, (start_time - time.monotonic()) * 1000 + timeout)
try:
data = await consumer.getmany(timeout_ms=timeout_left, max_records=1)
except GroupAuthorizationFailedError:
except (GroupAuthorizationFailedError, TopicAuthorizationFailedError):
KarapaceBase.r(body={"message": "Forbidden"}, content_type=content_type, status=HTTPStatus.FORBIDDEN)
except KafkaError as ex:
KarapaceBase.internal_error(
Expand Down

0 comments on commit 9a4f91e

Please sign in to comment.