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

[CT-700] [Bug] Logging tons of asterisks when sensitive env vars are missing #5312

Closed
1 task done
alexrosenfeld10 opened this issue May 31, 2022 · 2 comments · Fixed by #5518
Closed
1 task done
Labels
bug Something isn't working good_first_issue Straightforward + self-contained changes, good for new contributors! logging
Milestone

Comments

@alexrosenfeld10
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

When sensitive env vars are missing and are used in files, for example:

packages:
  - git: "https://{{ env_var('DBT_ENV_SECRET_GITHUB_TOKEN') }}@github.com/dbt-labs/dbt-utils.git"
    warn-unpinned: false

The logger seems to get a little trigger happy with the * symbol.

Here's an example:

❯ export DBT_ENV_SECRET_GITHUB_TOKEN=
❯ dbt deps
18:27:35  *****R*****u*****n*****n*****i*****n*****g***** *****w*****i*****t*****h***** *****d*****b*****t*****=*****1*****.*****1*****.*****0*****
18:27:39  *****E*****n*****c*****o*****u*****n*****t*****e*****r*****e*****d***** *****a*****n***** *****e*****r*****r*****o*****r*****:*****
***********************************E***********************************r***********************************r***********************************o***********************************r*********************************** ***********************************c***********************************h***********************************e***********************************c***********************************k***********************************i***********************************n***********************************g*********************************** ***********************************o***********************************u***********************************t*********************************** ***********************************s***********************************p***********************************e***********************************c***********************************=***********************************'***********************************N***********************************o***********************************n***********************************e***********************************'*********************************** ***********************************f***********************************o***********************************r*********************************** ***********************************r***********************************e***********************************p***********************************o*********************************** ***********************************h***********************************t***********************************t***********************************p***********************************s***********************************:***********************************/***********************************/***********************************@***********************************g***********************************i***********************************t***********************************h***********************************u***********************************b***********************************.***********************************c***********************************o***********************************m***********************************/***********************************d***********************************b***********************************t***********************************-***********************************l***********************************a***********************************b***********************************s***********************************/***********************************d***********************************b***********************************t***********************************-***********************************u***********************************t***********************************i***********************************l***********************************s***********************************.***********************************g***********************************i***********************************t***********************************
***********************************************************************************************************************************************************************************************************************f***********************************************************************************************************************************************************************************************************************a***********************************************************************************************************************************************************************************************************************t***********************************************************************************************************************************************************************************************************************a***********************************************************************************************************************************************************************************************************************l***********************************************************************************************************************************************************************************************************************:*********************************************************************************************************************************************************************************************************************** ***********************************************************************************************************************************************************************************************************************d***********************************************************************************************************************************************************************************************************************e***********************************************************************************************************************************************************************************************************************s***********************************************************************************************************************************************************************************************************************t***********************************************************************************************************************************************************************************************************************i***********************************************************************************************************************************************************************************************************************n***********************************************************************************************************************************************************************************************************************a***********************************************************************************************************************************************************************************************************************t***********************************************************************************************************************************************************************************************************************i***********************************************************************************************************************************************************************************************************************o***********************************************************************************************************************************************************************************************************************n*********************************************************************************************************************************************************************************************************************** ***********************************************************************************************************************************************************************************************************************p***********************************************************************************************************************************************************************************************************************a***********************************************************************************************************************************************************************************************************************t***********************************************************************************************************************************************************************************************************************h*********************************************************************************************************************************************************************************************************************** ***********************************************************************************************************************************************************************************************************************'***********************************************************************************************************************************************************************************************************************5***********************************************************************************************************************************************************************************************************************8***********************************************************************************************************************************************************************************************************************8***********************************************************************************************************************************************************************************************************************1***********************************************************************************************************************************************************************************************************************e***********************************************************************************************************************************************************************************************************************4***********************************************************************************************************************************************************************************************************************c***********************************************************************************************************************************************************************************************************************3***********************************************************************************************************************************************************************************************************************4***********************************************************************************************************************************************************************************************************************0***********************************************************************************************************************************************************************************************************************5***********************************************************************************************************************************************************************************************************************9***********************************************************************************************************************************************************************************************************************7***********************************************************************************************************************************************************************************************************************4***********************************************************************************************************************************************************************************************************************2***********************************************************************************************************************************************************************************************************************c***********************************************************************************************************************************************************************************************************************e***********************************************************************************************************************************************************************************************************************6***********************************************************************************************************************************************************************************************************************a***********************************************************************************************************************************************************************************************************************4***********************************************************************************************************************************************************************************************************************a***********************************************************************************************************************************************************************************************************************0***********************************************************************************************************************************************************************************************************************a***********************************************************************************************************************************************************************************************************************5***********************************************************************************************************************************************************************************************************************e***********************************************************************************************************************************************************************************************************************0***********************************************************************************************************************************************************************************************************************6***********************************************************************************************************************************************************************************************************************6***********************************************************************************************************************************************************************************************************************c***********************************************************************************************************************************************************************************************************************7***********************************************************************************************************************************************************************************************************************b***********************************************************************************************************************************************************************************************************************d***********************************************************************************************************************************************************************************************************************'*********************************************************************************************************************************************************************************************************************** ***********************************************************************************************************************************************************************************************************************a***********************************************************************************************************************************************************************************************************************l***********************************************************************************************************************************************************************************************************************r***********************************************************************************************************************************************************************************************************************e***********************************************************************************************************************************************************************************************************************a***********************************************************************************************************************************************************************************************************************d***********************************************************************************************************************************************************************************************************************y*********************************************************************************************************************************************************************************************************************** ***********************************************************************************************************************************************************************************************************************e***********************************************************************************************************************************************************************************************************************x***********************************************************************************************************************************************************************************************************************i***********************************************************************************************************************************************************************************************************************s***********************************************************************************************************************************************************************************************************************t***********************************************************************************************************************************************************************************************************************s*********************************************************************************************************************************************************************************************************************** ***********************************************************************************************************************************************************************************************************************a***********************************************************************************************************************************************************************************************************************n***********************************************************************************************************************************************************************************************************************d*********************************************************************************************************************************************************************************************************************** ***********************************************************************************************************************************************************************************************************************i***********************************************************************************************************************************************************************************************************************s*********************************************************************************************************************************************************************************************************************** ***********************************************************************************************************************************************************************************************************************n***********************************************************************************************************************************************************************************************************************o***********************************************************************************************************************************************************************************************************************t*********************************************************************************************************************************************************************************************************************** ***********************************************************************************************************************************************************************************************************************a***********************************************************************************************************************************************************************************************************************n*********************************************************************************************************************************************************************************************************************** ***********************************************************************************************************************************************************************************************************************e***********************************************************************************************************************************************************************************************************************m***********************************************************************************************************************************************************************************************************************p***********************************************************************************************************************************************************************************************************************t***********************************************************************************************************************************************************************************************************************y*********************************************************************************************************************************************************************************************************************** ***********************************************************************************************************************************************************************************************************************d***********************************************************************************************************************************************************************************************************************i***********************************************************************************************************************************************************************************************************************r***********************************************************************************************************************************************************************************************************************e***********************************************************************************************************************************************************************************************************************c***********************************************************************************************************************************************************************************************************************t***********************************************************************************************************************************************************************************************************************o***********************************************************************************************************************************************************************************************************************r***********************************************************************************************************************************************************************************************************************y***********************************************************************************************************************************************************************************************************************.***********************************************************************************************************************************************************************************************************************
***********************************************************************************************************************************************************************************************************************

Another example:

❯ dbt run --select foo
18:28:40  *****R*****u*****n*****n*****i*****n*****g***** *****w*****i*****t*****h***** *****d*****b*****t*****=*****1*****.*****1*****.*****0*****
18:28:41  *****F*****o*****u*****n*****d***** *****2***** *****m*****o*****d*****e*****l*****s*****,***** *****4***** *****t*****e*****s*****t*****s*****,***** *****0***** *****s*****n*****a*****p*****s*****h*****o*****t*****s*****,***** *****0***** *****a*****n*****a*****l*****y*****s*****e*****s*****,***** *****4*****0*****6***** *****m*****a*****c*****r*****o*****s*****,***** *****0***** *****o*****p*****e*****r*****a*****t*****i*****o*****n*****s*****,***** *****0***** *****s*****e*****e*****d***** *****f*****i*****l*****e*****s*****,***** *****0***** *****s*****o*****u*****r*****c*****e*****s*****,***** *****0***** *****e*****x*****p*****o*****s*****u*****r*****e*****s*****,***** *****0***** *****m*****e*****t*****r*****i*****c*****s*****
18:28:41  *****

Expected Behavior

Probably a few hundred fewer asterisks. Maybe still some asterisks, but definitely way, way fewer.

Steps To Reproduce

  1. dbt init
  2. make a packages.yml and use a DBT_ENV_SECRET_BLAH type env var
  3. make sure your DBT_ENV_SECRET_BLAH env var doesn't exist
  4. Run anything
  5. Obtain a lifetime supply of asterisks

Interestingly, the dbt.log file also is riddled with asterisks, in case the console output didn't have enough for ya 😉

foo.zip

Relevant log output

See foo.zip for dbt project including logs

Environment

- OS: macOS
- Python: 
❯ python --version
Python 3.7.9
- dbt:
❯ dbt --version
Core:
  - installed: 1.1.0
  - latest:    1.1.0 - Up to date!

Plugins:
  - snowflake: 1.1.0 - Up to date!

What database are you using dbt with?

snowflake

Additional Context

No response

@alexrosenfeld10 alexrosenfeld10 added bug Something isn't working triage labels May 31, 2022
@github-actions github-actions bot changed the title [Bug] Logging tons of asterisks when sensitive env vars are missing [CT-700] [Bug] Logging tons of asterisks when sensitive env vars are missing May 31, 2022
@emmyoop
Copy link
Member

emmyoop commented Jul 20, 2022

@alexrosenfeld10 thanks for being patient while we found some time to take a look at this!

I was able to replicate this but the cause is slightly different than you indicate. When the secret environment variable truely does not exist you'll get an appropriate error:

22:08:32  Encountered an error:
Parsing Error
  Env var required but not provided: 'DBT_ENV_SECRET_NOTHING'

However, when you set it to an empty string

export DBT_ENV_SECRET_NOTHING=''

You start to get all the asterisks. This is because we're seeing an empty string as a secret. So we add asterisks between every character. If you look closely at your above log messages....

18:27:35  *****R*****u*****n*****n*****i*****n*****g***** *****w*****i*****t*****h***** *****d*****b*****t*****=*****1*****.*****1*****.*****0*****

is

18:27:35  Running with dbt 1.1.0

when you strip out all the asterisks. Obviously not what we intend. This is definitely a bug, if an obscure one.

The solution here would be to make sure the empty string is not included as a secret. The place to do that would be:

def env_secrets() -> List[str]:
return [v for k, v in os.environ.items() if k.startswith(SECRET_ENV_PREFIX)]

It needs to be modified to ignore both empty string and strings consisting of just spaces:

def env_secrets() -> List[str]: 
     return [v for k, v in os.environ.items() if k.startswith(SECRET_ENV_PREFIX) and v.strip()] 

I'm going to mark this as a good first issue as it's a straight forward fix.

@emmyoop emmyoop added good_first_issue Straightforward + self-contained changes, good for new contributors! and removed triage labels Jul 20, 2022
@Goodkat
Copy link
Contributor

Goodkat commented Jul 23, 2022

@emmyoop Could you maybe assign it to me?

@emmyoop emmyoop linked a pull request Jul 25, 2022 that will close this issue
6 tasks
@emmyoop emmyoop linked a pull request Jul 25, 2022 that will close this issue
6 tasks
@jtcohen6 jtcohen6 added this to the v1.3 milestone Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good_first_issue Straightforward + self-contained changes, good for new contributors! logging
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants