Skip to content

fix(tls): bypass N_TTY 4096-byte limit for certificate input prompts#807

Draft
hemanthnakkina wants to merge 1 commit into
canonical:mainfrom
hemanthnakkina:fix-ca-chain-tty-truncation
Draft

fix(tls): bypass N_TTY 4096-byte limit for certificate input prompts#807
hemanthnakkina wants to merge 1 commit into
canonical:mainfrom
hemanthnakkina:fix-ca-chain-tty-truncation

Conversation

@hemanthnakkina
Copy link
Copy Markdown
Collaborator

The Linux kernel N_TTY line discipline silently truncates input pasted into a terminal at 4095 characters in canonical (ICANON) mode. Base64-encoded CA chains with multiple intermediate CAs routinely exceed this limit, causing 'Unable to encode CA chain' errors.

Add LargeInputStreamWrapper and LargeInputPromptQuestion to sunbeam/core/questions.py. When stdin is a TTY, the new stream clears only the ICANON termios flag before reading, bypassing the N_TTY 4096-byte buffer limit. All other terminal behaviour is preserved: ECHO (user sees their paste), ISIG (Ctrl+C works), and IEXTEN remain set. Terminal settings are always restored in a finally block.

Switch certificate, ca-certificate, and ca-chain prompts in sunbeam/features/tls/common.py and
sunbeam/features/loadbalancer/feature.py to use
LargeInputPromptQuestion. All other prompts are unaffected.

Add unit tests covering _read_line_no_icanon(), LargeInputStreamWrapper, and LargeInputPromptQuestion: input beyond 4096 chars, ICANON-only clearing, terminal restore on success and KeyboardInterrupt, backspace handling, non-TTY fallback, and preseed/accept_defaults paths.

Closes: https://bugs.launchpad.net/snap-openstack/+bug/2155219

Assisted-By: Claude Sonnet 4.6 noreply@anthropic.com

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses Linux N_TTY canonical-mode input truncation (4095 chars) that breaks pasting long base64-encoded certificate/CA-chain material into interactive prompts, by introducing a TTY-specific input stream that temporarily disables ICANON while reading.

Changes:

  • Add _read_line_no_icanon(), LargeInputStreamWrapper, and LargeInputPromptQuestion to bypass canonical-mode truncation for large pasted inputs.
  • Switch certificate-related prompts in TLS and loadbalancer features to use LargeInputPromptQuestion.
  • Add unit/integration-style tests validating long-input behavior, ICANON-only clearing, and terminal restoration.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
sunbeam-python/sunbeam/core/questions.py Introduces large-input TTY reading (ICANON off) and routes Question.ask() through an overridable input stream.
sunbeam-python/sunbeam/features/tls/common.py Uses LargeInputPromptQuestion for certificate prompt to avoid truncation.
sunbeam-python/sunbeam/features/loadbalancer/feature.py Uses LargeInputPromptQuestion for certificate/CA certificate/CA chain prompts.
sunbeam-python/tests/unit/sunbeam/core/test_questions.py Adds coverage for large-input stream behavior and PTY-based truncation demonstration tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread sunbeam-python/sunbeam/core/questions.py
Comment thread sunbeam-python/sunbeam/core/questions.py Outdated
Comment thread sunbeam-python/tests/unit/sunbeam/core/test_questions.py
The Linux kernel N_TTY line discipline silently truncates input pasted
into a terminal at 4095 characters in canonical (ICANON) mode.
Base64-encoded CA chains with multiple intermediate CAs routinely
exceed this limit, causing 'Unable to encode CA chain' errors.

Add LargeInputStreamWrapper and LargeInputPromptQuestion to
sunbeam/core/questions.py. When stdin is a TTY, the new stream
clears only the ICANON termios flag before reading, bypassing the
N_TTY 4096-byte buffer limit. All other terminal behaviour is
preserved: ECHO (user sees their paste), ISIG (Ctrl+C works),
and IEXTEN remain set. Terminal settings are always restored in
a finally block.

Switch certificate, ca-certificate, and ca-chain prompts in
sunbeam/features/tls/common.py and
sunbeam/features/loadbalancer/feature.py to use
LargeInputPromptQuestion. All other prompts are unaffected.

Add unit tests covering _read_line_no_icanon(), LargeInputStreamWrapper,
and LargeInputPromptQuestion: input beyond 4096 chars, ICANON-only
clearing, terminal restore on success and KeyboardInterrupt, backspace
handling, non-TTY fallback, and preseed/accept_defaults paths.

Closes: https://bugs.launchpad.net/snap-openstack/+bug/2155219

Assisted-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Hemanth Nakkina <hemanth.nakkina@canonical.com>
@hemanthnakkina hemanthnakkina force-pushed the fix-ca-chain-tty-truncation branch from b4be140 to 41dffbc Compare June 4, 2026 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants