Harden gateway security: secrets, authz, and input validation - #2183
Closed
quantova-inc wants to merge 1 commit into
Closed
Harden gateway security: secrets, authz, and input validation#2183quantova-inc wants to merge 1 commit into
quantova-inc wants to merge 1 commit into
Conversation
Address a set of security issues found during an audit of the gateway, client, and deployment config: - settings: fail closed when DJANGO_SECRET_KEY is unset and DEBUG is off; default DEBUG to 0 and require an explicit ALLOWED_HOSTS in production; fail closed on an unknown SETTINGS_AUTH_MECHANISM instead of silently falling back to the mock_token backend. - crypto: derive the token-encryption Fernet key with SHA-256 (full entropy) instead of space-padding the secret; add an optional dedicated TOKENS_ENCRYPTION_KEY; decrypt_env_vars now fails closed (drops a value it cannot decrypt rather than injecting ciphertext into the runtime env). - images: validate the container image reference grammar and enforce a registry path boundary so "registry" is not matched by "registry.attacker.com/...". - entrypoint: validate it is a relative .py path with no ".." or shell characters before it is interpolated into the runner command. - jobs: provider get_jobs listings no longer serialize other authors' private result field. - fleets: reject path-traversal members when uploading the artifact tar to COS; drop the duplicate plaintext ENV_JOB_ARGUMENTS literal env var (arguments are delivered via COS at ARGUMENTS_PATH). - templates: move the extra template directory off world-writable /tmp/templates to /etc/gateway/templates (env-overridable) and update the chart mount. - serializers: give the base Job/Program serializers explicit field allowlists so env_vars/account_id/instance_crn are never serialized implicitly. - client: basename the download target so a crafted name cannot escape the download directory; type-validate the result decoder payload. - docker-compose: provide a local dev secret key and ALLOWED_HOSTS so the new fail-closed boot still works locally.
|
|
Member
|
@quantova-inc thanks for your contribution, do you mind to sign the CLA? |
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR addresses a set of security issues found while auditing the gateway, client, and deployment configuration. Each change is defensive and aims to fail closed.
Configuration / secrets
DJANGO_SECRET_KEYis unset andDEBUGis off, instead of silently using a public hardcoded key. A hardcoded fallback remains only forDEBUG/tests.DEBUGnow defaults to0;ALLOWED_HOSTSdefaults tolocalhost(not*) in production.SETTINGS_AUTH_MECHANISMnow raises instead of silently falling back to themock_tokenbackend.TOKENS_ENCRYPTION_KEY.decrypt_env_varsnow drops a value it cannot decrypt rather than injecting ciphertext into the runtime environment.Authorization / data exposure
get_jobs: provider listings no longer serialize other authors' privateresultfield.Job/Programserializers now use explicit field allowlists soenv_vars/account_id/instance_crnare never serialized implicitly.Input validation
registry.attacker.com/.....pypath with no..segments or shell characters before it is interpolated into the runner command...traversal members when uploading the artifact, and drop the duplicate plaintextENV_JOB_ARGUMENTSliteral env var (arguments are delivered via COS atARGUMENTS_PATH).Templates / deployment
/tmp/templatesto/etc/gateway/templates(env-overridable viaGATEWAY_TEMPLATES_DIR) and update the Helm chart mount.docker-compose.yamlnow provides a local dev secret key andALLOWED_HOSTSso the new fail-closed boot still works locally.Client
Testing
py_compilepasses on all changed Python files.tox -e py311suite was not run in my local environment (Python 3.11 + Ray/Qiskit not available); CI should exercise it.Notes
literalenv vars; migrating them tosecret_key_refis left as a follow-up as it touches the fleet-submission flow more broadly.