Skip to content

Conversation

@haseebmalik18
Copy link

Closes #20719

Adds Kerberos authentication support to Python HadoopFileSystem via new --hdfs_client flag.

Changes:

  • Added --hdfs_client option (default: INSECURE, new: KERBEROS)
  • Uses hdfs.ext.kerberos.KerberosClient for Kerberos mode
  • Added requests-kerberos dependency to hadoop extra
  • 6 new unit tests covering both authentication modes

Usage:

options = PipelineOptions([                                                                                                                          
    '--hdfs_client=KERBEROS',                                                                                                                        
    '--hdfs_host=namenode.com',                                                                                                                      
    '--hdfs_port=9871',                                                                                                                              
    '--hdfs_user=user',                                                                                                                              
])

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @haseebmalik18, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the Python HadoopFileSystem by integrating Kerberos authentication, providing a secure way to interact with HDFS. It introduces a new configuration option to switch between insecure and Kerberos-based client types, ensuring that users can leverage robust security protocols when accessing their Hadoop Distributed File System resources. This change significantly improves the security posture for Beam pipelines interacting with HDFS.

Highlights

  • Kerberos Authentication for HadoopFileSystem: Added support for Kerberos authentication to the Python HadoopFileSystem, allowing users to connect to secured HDFS clusters.
  • New --hdfs_client Flag: Introduced a new pipeline option --hdfs_client which accepts INSECURE (default) or KERBEROS to specify the authentication method for HDFS connections.
  • Dependency Update: The requests-kerberos library has been added as a dependency to the hadoop extra, required for Kerberos authentication.
  • Comprehensive Unit Tests: Six new unit tests were added to cover both INSECURE and KERBEROS authentication modes, including scenarios for missing Kerberos libraries.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link
Contributor

Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment assign set of reviewers

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds Kerberos authentication support to the HadoopFileSystem, which is a great feature. The implementation is clean and follows existing patterns in the codebase. I've added a few suggestions to improve robustness and error handling. The new unit tests are comprehensive and cover the new functionality well. I also noticed a minor formatting issue in the CHANGES.md file.

## Highlights

- For versions 2.19.0 and older release notes are available on [Apache Beam Blog](https://beam.apache.org/blog/).
- - For versions 2.19.0 and older release notes are available on [Apache Beam Blog](https://beam.apache.org/blog/).
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

It seems like there's an extra hyphen - here, which will render as a nested list item. Was this intentional? If not, it should probably be removed to maintain consistent formatting.

Suggested change
- - For versions 2.19.0 and older release notes are available on [Apache Beam Blog](https://beam.apache.org/blog/).
- For versions 2.19.0 and older release notes are available on [Apache Beam Blog](https://beam.apache.org/blog/).


# Create HDFS client based on authentication type
url = 'http://%s:%s' % (hdfs_host, str(hdfs_port))
if hdfs_client == 'KERBEROS':
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To make the client selection more robust, it would be good to perform a case-insensitive comparison. While argparse enforces the choices case-sensitively, options can also be passed as a dictionary where case might not be consistent. Using .upper() would handle KERBEROS, kerberos, etc.

Suggested change
if hdfs_client == 'KERBEROS':
if hdfs_client.upper() == 'KERBEROS':

Comment on lines +160 to +164
except Exception as e:
raise RuntimeError(
'Failed to create KerberosClient. Ensure you have valid Kerberos '
'credentials (run kinit) or have configured a keytab. '
'Error: %s' % str(e))
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

When re-raising the exception, it's better to use raise from to preserve the original exception's traceback. This is very helpful for debugging. The current implementation hides the original exception type and stack trace.

Also, consider using an f-string for formatting the error message for better readability, as the project seems to be on a modern Python version.

Suggested change
except Exception as e:
raise RuntimeError(
'Failed to create KerberosClient. Ensure you have valid Kerberos '
'credentials (run kinit) or have configured a keytab. '
'Error: %s' % str(e))
except Exception as e:
raise RuntimeError(
'Failed to create KerberosClient. Ensure you have valid Kerberos '
'credentials (run kinit) or have configured a keytab. '
f'Error: {e}') from e

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.

Python HDFS: add Kerberos authentication support

1 participant