Skip to content

PHPC-2356: Remove explicit env variables #1514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 7, 2024

Conversation

alcaeus
Copy link
Member

@alcaeus alcaeus commented Feb 5, 2024

PHPC-2356
This will prevent accidental leaking of environment variables.

Note that the URI list for Atlas connectivity tests are now contained in an environment variable in the project config, which is added to the environment via the include_expansions_in_env option in run tests. This makes it available for us to use in tests without having to decrypt a file and potentially leak the encryption credentials.

@alcaeus alcaeus requested a review from jmikola February 5, 2024 13:51
@alcaeus alcaeus self-assigned this Feb 5, 2024
@@ -19,7 +19,7 @@ buildvariants:
- ".sharded .local !.3.6 !.4.0 !.4.2 !.4.4 !.5.0"
- ".loadbalanced .local !.3.6 !.4.0 !.4.2 !.4.4 !.5.0"
- "test-atlas-connectivity"
- ".ocsp !.4.4"
- ".ocsp !.4.4 !.5.0"
Copy link
Member

Choose a reason for hiding this comment

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

IIUC, this drops OCSP testing on 5.0. What the impetus for this change? The OCSP spec test README doesn't talk about server versions.

Copy link
Member Author

Choose a reason for hiding this comment

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

We only test 6.0 and newer on Debian 11 - 5.0 and older are tested on Debian 9.2. OCSP tests for 5.0 are included in the test-debian92-php82-local matrix below.

- command: shell.exec
params:
script: |
openssl aes-256-cbc -S "${encrypted_uris_salt}" -K "${encrypted_uris_key}" -iv "${encrypted_uris_iv}" -in ${PROJECT_DIRECTORY}/.evergreen/atlas-uris.txt.enc -out ${PROJECT_DIRECTORY}/.evergreen/atlas-uris.txt -d
Copy link
Member

Choose a reason for hiding this comment

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

This makes it available for us to use in tests without having to decrypt a file and potentially leak the encryption credentials.

Are other drivers doing this as well? I don't have an opinion on which is more secure, but storing the URIs directly in the Evergreen project config is certainly more convenient.

Note: you can also remove .evergreen/atlas-uris.txt from .gitignore.

${PROJECT_DIRECTORY}/.evergreen/run-ocsp-responder.sh

"run tests":
- command: shell.exec
type: test
params:
include_expansions_in_env:
- API_VERSION
- ATLAS_CONNECTIVITY_URIS
Copy link
Member

Choose a reason for hiding this comment

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

Should this always be specified? In the test-atlas-connectivity task, run tests is invoked with vars: { TESTS: "tests/atlas.phpt" }, so I would expect that's the only case where you'd actually want to pass this potentially sensitive environment variable onwards.

Copy link
Member Author

Choose a reason for hiding this comment

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

I could create a separate function to run just the connectivity tests that also passes the necessary expansion to the env, but this would entail duplicating all of the logic in this function. I don't think it's worth it, as any attacker who might modify tests to get access to this environment variable would be able to do so in the particular test that includes this variable.

@@ -167,9 +167,19 @@ functions:
"bootstrap mongo-orchestration":
- command: shell.exec
params:
include_expansions_in_env:
Copy link
Member

Choose a reason for hiding this comment

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

Noted that vars (when calling a func) actually define expansions (per Functions). That distinction wasn't clear to me before this PR.

@@ -4,7 +4,7 @@ set -o errexit # Exit the script with error if any of the commands fail
# Supported environment variables
API_VERSION=${API_VERSION:-} # Optional API_VERSION environment variable for run-tests.php
CRYPT_SHARED_LIB_PATH="${CRYPT_SHARED_LIB_PATH:-}" # Optional path to crypt_shared library
MONGODB_URI=${MONGODB_URI:-} # Connection string (including credentials and topology info)
MONGODB_URI=${MONGODB_URI:-}${APPEND_URI:-} # Connection string (including credentials and topology info)
Copy link
Member

Choose a reason for hiding this comment

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

Nit: the "Supported environment variables" section here doubles as documentation, so I think it'd be clearer to take APPEND_URI separately in the same form and then merge them below.

That said, it's only essential that this merging happens before the "Determine if MONGODB_URI already has a query string" logic below.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. I've moved the merging of APPEND_URI to before detecting the suffix.

@alcaeus alcaeus requested a review from jmikola February 6, 2024 11:45
Co-authored-by: Jeremy Mikola <[email protected]>
@alcaeus alcaeus merged commit d4170f7 into mongodb:v1.17 Feb 7, 2024
@alcaeus alcaeus deleted the remove-explicit-env-variables branch February 7, 2024 08:03
alcaeus added a commit that referenced this pull request Feb 7, 2024
* v1.17:
  PHPC-2356: Remove explicit env variables (#1514)
  Upgrade to latest libmongoc and libmongocrypt versions (#1509)
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