Skip to content

fix: validate OFFLINE_PUBLISH_ALLOWED_PROTOCOLS entries - #231

Merged
PromiseFru merged 2 commits into
smswithoutborders:stagingfrom
ShahadatTest:fix/220-offline-protocol-validation
Nov 10, 2026
Merged

PromiseFru merged 2 commits into
smswithoutborders:stagingfrom
ShahadatTest:fix/220-offline-protocol-validation

Conversation

@ShahadatTest

@ShahadatTest ShahadatTest commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

OFFLINE_PUBLISH_ALLOWED_PROTOCOLS accepts only https and smtp, normalizes case and removes duplicates. Invalid values fail configuration validation instead of silently discarding offline payloads. Fixes #220. The PR targets staging.

Review follow-up:

  • Retain invalid entries while reporting them, so an unknown-only list such as smpt does not become an empty allow-all list and spuriously require an HTTPS shared secret.
  • Deduplicate case-insensitively and cover smtp,SMTP.
  • Cover uppercase HTTPS requiring the shared secret.
  • Document that invalid protocols fail manage.sh check and prevent startup.

Validation on an isolated Linux checkout / Python 3.12.3:

  • The strengthened invalid-protocol regressions fail twice against the prior PR loader (smpt/http); one mixed-list control passes.
  • make check test: all configured pre-commit hooks pass, including Ruff check/format, shell/Docker checks, Pyright and import-linter. Full suite: 521 passed, one existing Starlette/httpx deprecation warning.
  • git diff --check passes.

Generated the gRPC sources and reused the task-local native payload-specs bindings for validation. Generated sources, the development environment and test tooling are not included in this update. Database-dialect/systemd E2E suites and a manual documentation book build were not rerun.

AI assistance: the original contribution was AI-assisted. Cursor/Grok prepared the review patch; OpenAI Codex inspected it, completed the missing uppercase-HTTPS/documentation requests and independently ran the checks above at the account owner's request. No independent human review or personal production incident is claimed.

@PromiseFru

Copy link
Copy Markdown
Member

Thanks for the PR. Please follow the contribution guide: pull requests go to staging, not main, so rebase onto upstream/staging and change the base branch. Then make sure make check test passes on the whole suite. make check currently fails on a ruff line length error in publisher/config.py.

@github-actions github-actions Bot added the not-following-guidelines The PR doesn't follow CONTRIBUTING.md yet label Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Thank you, the base branch and tests now follow the contribution guide.

@ShahadatTest
ShahadatTest force-pushed the fix/220-offline-protocol-validation branch from 3bdde43 to 6b60c62 Compare November 6, 2026 08:02
@ShahadatTest
ShahadatTest changed the base branch from main to staging November 6, 2026 08:02
@github-actions github-actions Bot removed the not-following-guidelines The PR doesn't follow CONTRIBUTING.md yet label Nov 6, 2026

@PromiseFru PromiseFru left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you, the fix looks good. A few suggestions below.

Comment thread publisher/config.py Outdated
Comment on lines +349 to +360
allowed: list[str] = []
for protocol in read.get_list("OFFLINE_PUBLISH_ALLOWED_PROTOCOLS"):
choice = protocol.lower()
if choice not in OFFLINE_PUBLISH_PROTOCOLS:
read.fail(
"OFFLINE_PUBLISH_ALLOWED_PROTOCOLS",
f"expected one of {', '.join(OFFLINE_PUBLISH_PROTOCOLS)}, "
f"got {protocol!r}",
)
continue
if choice not in allowed:
allowed.append(choice)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

continue drops unknown entries, so smpt leaves the list empty, which counts as "allow every protocol" in the secret check. It then also reports OFFLINE_PUBLISH_SHARED_SECRET: is required, for an https setup the operator never enabled. Keeping the entries in the list fixes this and matches PlatformsConfig.load:

Suggested change
allowed: list[str] = []
for protocol in read.get_list("OFFLINE_PUBLISH_ALLOWED_PROTOCOLS"):
choice = protocol.lower()
if choice not in OFFLINE_PUBLISH_PROTOCOLS:
read.fail(
"OFFLINE_PUBLISH_ALLOWED_PROTOCOLS",
f"expected one of {', '.join(OFFLINE_PUBLISH_PROTOCOLS)}, "
f"got {protocol!r}",
)
continue
if choice not in allowed:
allowed.append(choice)
names = read.get_list("OFFLINE_PUBLISH_ALLOWED_PROTOCOLS")
allowed = list(dict.fromkeys(name.lower() for name in names))
for protocol in allowed:
if protocol not in OFFLINE_PUBLISH_PROTOCOLS:
read.fail(
"OFFLINE_PUBLISH_ALLOWED_PROTOCOLS",
f"expected one of {', '.join(OFFLINE_PUBLISH_PROTOCOLS)}, "
f"got {protocol!r}",
)

Comment thread tests/test_config.py
("smtp", ["smtp"]),
("SMTP", ["smtp"]),
("https,smtp", ["https", "smtp"]),
("smtp,smtp", ["smtp"]),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Entries that differ only in case should dedupe too:

Suggested change
("smtp,smtp", ["smtp"]),
("smtp,SMTP", ["smtp"]),

Comment thread tests/test_config.py Outdated
Comment on lines +230 to +233
assert "OFFLINE_PUBLISH_ALLOWED_PROTOCOLS" in errors(
OFFLINE_PUBLISH_ALLOWED_PROTOCOLS=protocols,
OFFLINE_PUBLISH_SHARED_SECRET=KEY,
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Passing the secret hides the extra error, so test without it:

Suggested change
assert "OFFLINE_PUBLISH_ALLOWED_PROTOCOLS" in errors(
OFFLINE_PUBLISH_ALLOWED_PROTOCOLS=protocols,
OFFLINE_PUBLISH_SHARED_SECRET=KEY,
)
problems = errors(OFFLINE_PUBLISH_ALLOWED_PROTOCOLS=protocols)
assert "OFFLINE_PUBLISH_ALLOWED_PROTOCOLS" in problems
assert "OFFLINE_PUBLISH_SHARED_SECRET" not in problems

@PromiseFru

Copy link
Copy Markdown
Member

Normalizing shouldn't let HTTPS skip the secret. Please add "HTTPS" to the list on test_offline_https_requires_shared_secret in tests/test_config.py: ["https", "HTTPS", "smtp,https", ""].

@PromiseFru

Copy link
Copy Markdown
Member

Please add this to Rules in docs/configuration/offline-publishing.md, since this now stops the services:

- Listing anything other than the protocols above fails `manage.sh check`, and the services refuse to start.

@PromiseFru PromiseFru left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you, this looks good!

@PromiseFru
PromiseFru merged commit bce8e5f into smswithoutborders:staging Nov 10, 2026
15 of 16 checks passed
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.

A typo in OFFLINE_PUBLISH_ALLOWED_PROTOCOLS discards every offline payload

2 participants