Repository navigation
fix: validate OFFLINE_PUBLISH_ALLOWED_PROTOCOLS entries - #231
PromiseFru merged 2 commits into
Conversation
|
Thanks for the PR. Please follow the contribution guide: pull requests go to |
|
Thank you, the base branch and tests now follow the contribution guide. |
3bdde43 to
6b60c62
Compare
PromiseFru
left a comment
There was a problem hiding this comment.
Thank you, the fix looks good. A few suggestions below.
| 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) |
There was a problem hiding this comment.
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:
| 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}", | |
| ) |
| ("smtp", ["smtp"]), | ||
| ("SMTP", ["smtp"]), | ||
| ("https,smtp", ["https", "smtp"]), | ||
| ("smtp,smtp", ["smtp"]), |
There was a problem hiding this comment.
Entries that differ only in case should dedupe too:
| ("smtp,smtp", ["smtp"]), | |
| ("smtp,SMTP", ["smtp"]), |
| assert "OFFLINE_PUBLISH_ALLOWED_PROTOCOLS" in errors( | ||
| OFFLINE_PUBLISH_ALLOWED_PROTOCOLS=protocols, | ||
| OFFLINE_PUBLISH_SHARED_SECRET=KEY, | ||
| ) |
There was a problem hiding this comment.
Passing the secret hides the extra error, so test without it:
| 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 |
|
Normalizing shouldn't let |
|
Please add this to Rules in - Listing anything other than the protocols above fails `manage.sh check`, and the services refuse to start. |
PromiseFru
left a comment
There was a problem hiding this comment.
Thank you, this looks good!
OFFLINE_PUBLISH_ALLOWED_PROTOCOLSaccepts onlyhttpsandsmtp, normalizes case and removes duplicates. Invalid values fail configuration validation instead of silently discarding offline payloads. Fixes #220. The PR targetsstaging.Review follow-up:
smptdoes not become an empty allow-all list and spuriously require an HTTPS shared secret.smtp,SMTP.HTTPSrequiring the shared secret.manage.sh checkand prevent startup.Validation on an isolated Linux checkout / Python 3.12.3:
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 --checkpasses.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.