Skip to content
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

Backport #5382 to 1.1.latest #5415

Merged
merged 2 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changes/unreleased/Under the Hood-20220616-120516.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Under the Hood
body: 'Add annotation to render_value method reimplemented in #5334'
time: 2022-06-16T12:05:16.474078+02:00
custom:
Author: jtcohen6
Issue: "4796"
PR: "5382"
1 change: 1 addition & 0 deletions .changie.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ kinds:
- label: Docs
- label: Under the Hood
- label: Dependencies
- label: Security
custom:
- key: Author
label: GitHub Username(s) (separated by a single space if multiple)
Expand Down
5 changes: 5 additions & 0 deletions core/dbt/config/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,12 @@ def name(self):
return "Secret"

def render_value(self, value: Any, keypath: Optional[Keypath] = None) -> Any:
# First, standard Jinja rendering, with special handling for 'secret' environment variables
# "{{ env_var('DBT_SECRET_ENV_VAR') }}" -> "$$$DBT_SECRET_START$$$DBT_SECRET_ENV_{VARIABLE_NAME}$$$DBT_SECRET_END$$$"
# This prevents Jinja manipulation of secrets via macros/filters that might leak partial/modified values in logs
rendered = super().render_value(value, keypath)
# Now, detect instances of the placeholder value ($$$DBT_SECRET_START...DBT_SECRET_END$$$)
# and replace them with the actual secret value
if SECRET_ENV_PREFIX in str(rendered):
search_group = f"({SECRET_ENV_PREFIX}(.*))"
pattern = SECRET_PLACEHOLDER.format(search_group).replace("$", r"\$")
Expand Down
23 changes: 23 additions & 0 deletions test/integration/013_context_var_tests/test_context_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,29 @@ def test_postgres_fail_clone_with_scrubbing(self):
assert "abc123" not in str(exc.exception)


class TestCloneFailSecretNotRendered(TestCloneFailSecretScrubbed):

@property
def packages_config(self):
return {
"packages": [
{
"git": "https://fakeuser:{{ env_var('DBT_ENV_SECRET_GIT_TOKEN') | join(' ') }}@github.com/dbt-labs/fake-repo.git"
},
]
}

@use_profile('postgres')
def test_postgres_fail_clone_with_scrubbing(self):
with self.assertRaises(dbt.exceptions.InternalException) as exc:
_, log_output = self.run_dbt_and_capture(["deps"])

# we should not see any manipulated form of the secret value (abc123) here
# we should see a manipulated form of the placeholder instead
assert "a b c 1 2 3" not in str(exc.exception)
assert "D B T _ E N V _ S E C R E T _ G I T _ T O K E N" in str(exc.exception)


class TestEmitWarning(DBTIntegrationTest):
@property
def schema(self):
Expand Down