You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "haroldfabla2-hue (via GitHub)" <gi...@apache.org> on 2026/06/22 22:20:32 UTC

[PR] fix: Add port validation (0-65535) for Airflow connections [airflow]

haroldfabla2-hue opened a new pull request, #68863:
URL: https://github.com/apache/airflow/pull/68863

   ## Summary
   This PR adds validation to ensure that the `port` field in Airflow connections is a valid TCP/UDP port number (0-65535).
   
   Previously, users could create connections with invalid port values like -1, 99999999, or any other integer outside the valid range, and Airflow would accept and persist them without complaint.
   
   ## Changes
   - Added `_validate_port()` function in `airflow.models.connection` to validate port range (0-65535)
   - Added validation in `Connection.__init__()` for individual connection creation
   - Added validation in `Connection._parse_from_uri()` for URI-based connection creation
   - Added `_validate_port()` static method in `airflow.sdk.definitions.connection` for Task SDK
   - Added validation in `Connection.__init__()` for Task SDK connection creation
   - Added validation in `Connection.from_uri()` for Task SDK URI-based connection creation
   - Added Pydantic `field_validator` in `api_fastapi/execution_api/datamodels.connection.ConnectionResponse` for REST API
   
   ## Affected Areas
   - Core connection model (`airflow.models.connection`)
   - Task SDK connection definition (`airflow.sdk.definitions.connection`)
   - Public REST API connection request schema (`api_fastapi/execution_api/datamodels/connection.py`)
   - Execution API connection schema (handled by Pydantic)
   
   ## Why Fix This
   Port numbers have a well-defined valid range by the TCP/IP specification (0-65535). Accepting values outside this range produces connections that can never work, with no feedback to the user at the point of creation. Validation should be enforced at the boundary, not discovered at runtime inside a hook or provider.
   
   ## Test Plan
   - Try creating a connection with port = -1 (should fail)
   - Try creating a connection with port = 99999999 (should fail)
   - Try creating a connection with port = 8080 (should succeed)
   - Try creating a connection with port = 0 (should succeed - reserved port)
   - Try creating a connection via URI with invalid port (should fail)
   
   ## Checklist
   - [x] My code follows the style guidelines of this project
   - [x] I have performed a self-review of my code
   - [x] I have commented my code, particularly in hard-to-understand areas
   - [x] I have made corresponding changes to the documentation
   
   Closes #68382


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix: Add port validation (0-65535) for Airflow connections [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #68863:
URL: https://github.com/apache/airflow/pull/68863#issuecomment-5021131381

   @haroldfabla2-hue This PR has been converted to **draft** because it does not yet meet our [Pull Request quality criteria](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-quality-criteria).
   
   **Issues found:**
   - :x: **Build docs**: Failing: `CI image checks / Build documentation (--docs-only)`, `CI image checks / Build documentation (--spellcheck-only)`. Run `breeze build-docs` locally to reproduce.
   - :x: **Pre-commit / static checks**: Failing: `CI image checks / Static checks`. Run `prek run --from-ref main --stage pre-commit` locally to reproduce and fix.
   
   > **Note:** Your branch is **607 commits behind `main`**. Some check failures may be caused by changes in the base branch rather than by your PR. Please rebase your branch and push again to get up-to-date CI results.
   
   **What to do next:**
   - Fix each issue listed above.
   - Make sure static checks pass locally (`prek run --from-ref main --stage pre-commit`).
   - Mark the PR as "Ready for review" when you're done.
   
   Converting a PR to draft is **not** a rejection — it is an invitation to bring the PR up to the project's standards so that maintainer review time is spent productively. There is no rush — take your time and work at your own pace. We appreciate your contribution and are happy to wait for updates. If you have questions, feel free to ask on the [Airflow Slack](https://s.apache.org/airflow-slack).
   
   ---
   
   _Note: This comment was drafted by an AI-assisted triage tool and may contain mistakes. Once you have addressed the points above, an Apache Airflow maintainer — a real person — will take the next look at your PR. We use this [two-stage triage process](https://github.com/apache/airflow/blob/main/contributing-docs/25_maintainer_pr_triage.md#why-the-first-pass-is-automated) so that our maintainers' limited time is spent where it matters most: the conversation with you._


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix: Add port validation (0-65535) for Airflow connections [airflow]

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk closed pull request #68863: fix: Add port validation (0-65535) for Airflow connections
URL: https://github.com/apache/airflow/pull/68863


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org