Skip to content

Kafka Connect: Handle AccessDeniedException in auto-create#16072

Open
yadavay-amzn wants to merge 1 commit into
apache:mainfrom
yadavay-amzn:fix/13758-access-denied-autocreate
Open

Kafka Connect: Handle AccessDeniedException in auto-create#16072
yadavay-amzn wants to merge 1 commit into
apache:mainfrom
yadavay-amzn:fix/13758-access-denied-autocreate

Conversation

@yadavay-amzn
Copy link
Copy Markdown
Contributor

@yadavay-amzn yadavay-amzn commented Apr 21, 2026

Summary

Fixes #13758.

When iceberg.tables.auto-create-enabled is set, the Kafka Connect sink connector calls GlueCatalog.createNamespace() which can throw software.amazon.awssdk.services.glue.model.AccessDeniedException if the user lacks glue:CreateDatabase permission. This exception was not caught, crashing the connector even when the database already exists.

Changes

Root cause fix — GlueCatalog.createNamespace():

  • Catch AccessDeniedException and wrap it as Iceberg's ForbiddenException, consistent with how GlueTableOperations already handles this exception for table operations.

Defense-in-depth — IcebergWriterFactory.createNamespaceIfNotExist():

  • Add NotAuthorizedException to the existing catch block alongside AlreadyExistsException and ForbiddenException, so auth exceptions from any catalog implementation are handled gracefully.

Testing

  • Added testCreateNamespaceAccessDenied in TestGlueCatalog: verifies AccessDeniedException is wrapped as ForbiddenException.
  • Added testCreateNamespaceHandlesForbiddenException and testCreateNamespaceHandlesNotAuthorizedException in TestIcebergWriterFactory: verifies both exception types are swallowed during namespace creation.

@yadavay-amzn yadavay-amzn force-pushed the fix/13758-access-denied-autocreate branch from eac974f to 4a1977d Compare April 21, 2026 22:01
@yadavay-amzn yadavay-amzn changed the title Kafka Connect: Handle AccessDeniedException in auto-create (#13758) Kafka Connect: Handle AccessDeniedException in auto-create May 12, 2026
@yadavay-amzn
Copy link
Copy Markdown
Contributor Author

@Baunsgaard @nastra Could you take a look when you get a chance? This handles AccessDeniedException gracefully in the Kafka Connect auto-create path when the user lacks glue:CreateDatabase permission. Fixed the PR title format as well.

@cloventt
Copy link
Copy Markdown

Wouldn't this approach still cause the connector to crash if glue.CreateDatabase permission does not exist? I don't think this solves the problem. Ideally we want the connector to proceed if the database already exists.

There is another approach that would work. The outer method is called createNamespaceIfNotExist(), which to me implies that we should first test to see if the namespace exists, and if it not, create it. We could call glue.getDatabase() first, and then only if we receive a EntityNotFoundException then we proceed to call glue.createDatabase(). This would mean that if the Glue database already exists the connector would proceed without ever attempting to invoke glue.createDatabase.

@yadavay-amzn yadavay-amzn force-pushed the fix/13758-access-denied-autocreate branch from 4a1977d to 8468b73 Compare May 12, 2026 02:27
@yadavay-amzn
Copy link
Copy Markdown
Contributor Author

@cloventt Good suggestion. Updated to check namespaceExists() first and only call createNamespace() if the namespace does not exist. This way users with read-only Glue access never hit the permission error when the database already exists. The catch block is kept as defense-in-depth for concurrent creation or other edge cases. Also added a test verifying that createNamespace is never called when the namespace already exists.

@cloventt
Copy link
Copy Markdown

Nice one, I submitted my own PR so the maintainers can choose whichever impl they prefer #16297.

@yadavay-amzn yadavay-amzn force-pushed the fix/13758-access-denied-autocreate branch from 8468b73 to a6128c8 Compare May 12, 2026 06:03
Copy link
Copy Markdown
Contributor

@Baunsgaard Baunsgaard left a comment

Choose a reason for hiding this comment

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

TBH, my feeling is that it should fail on these exception types, and only the AlreadyExistsException should be allowed to skip.

nsCatalog.createNamespace(namespace);
} catch (AlreadyExistsException | ForbiddenException | NotAuthorizedException ex) {
// Namespace may have been created concurrently, or the user lacks create permission
// but the namespace already exists. Either way, proceed gracefully.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems wrong to me. We should at minimum do a LOG.warning() to highlight that we have an conflict. I do see the old code did not do any logging, but if we add it we can get some statistics on how often this error is encountered.

@yadavay-amzn yadavay-amzn force-pushed the fix/13758-access-denied-autocreate branch from a6128c8 to e6a03e9 Compare May 13, 2026 17:06
@yadavay-amzn
Copy link
Copy Markdown
Contributor Author

@Baunsgaard Makes sense. Updated: the catch now only handles AlreadyExistsException (concurrent creation race) with a LOG.warn. Auth exceptions propagate so the user sees the real permission error.

@yadavay-amzn yadavay-amzn force-pushed the fix/13758-access-denied-autocreate branch from e6a03e9 to 7e50d6d Compare May 13, 2026 18:47
)

GlueCatalog.createNamespace() did not catch AccessDeniedException from
the AWS Glue SDK. When a user lacks glue:CreateDatabase permission, Glue
throws AccessDeniedException (HTTP 400) which propagated uncaught,
crashing the Kafka Connect connector even when the database already
exists.

This fix:
- Catches AccessDeniedException in GlueCatalog.createNamespace() and
  wraps it as ForbiddenException, consistent with how
  GlueTableOperations already handles this exception.
- Adds NotAuthorizedException to the catch block in
  IcebergWriterFactory.createNamespaceIfNotExist() for defense-in-depth
  against auth exceptions from any catalog implementation.

Closes apache#13758
@yadavay-amzn yadavay-amzn force-pushed the fix/13758-access-denied-autocreate branch from 7e50d6d to ac7d7b3 Compare May 14, 2026 02:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow AccessDeniedExceptions To Fail Silently On Auto Creating Tables

3 participants