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

lang/funcs: Redact sensitive values from function errors #30067

Merged

Conversation

alisdair
Copy link
Member

@alisdair alisdair commented Dec 1, 2021

Some function errors include values derived from arguments. This commit is the result of a manual audit of these errors, which resulted in:

  • Adding a helper function to redact sensitive values;
  • Applying that helper function where errors include values derived from possibly-sensitive arguments;
  • Cleaning up other errors which need not include those values, or were otherwise incorrect.

Fixes #30033

Example

$ echo 'base64decode("wheee")' | terraform console

│ Error: Error in function call

│   on <console-input> line 1:
│   (source code not available)

│ Call to function "base64decode" failed: failed to decode base64 data "wheee".


$ echo 'base64decode(sensitive("wheee"))' | terraform console

│ Error: Error in function call

│   on <console-input> line 1:
│   (source code not available)

│ Call to function "base64decode" failed: failed to decode base64 data (sensitive value).

@alisdair alisdair added functions 1.1-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged labels Dec 1, 2021
@alisdair alisdair requested a review from a team December 1, 2021 20:35
@alisdair alisdair self-assigned this Dec 1, 2021
log.Printf("[DEBUG] the result of decoding the provided string is not valid UTF-8: %s", sDec)
return cty.UnknownVal(cty.String), fmt.Errorf("the result of decoding the provided string is not valid UTF-8")
log.Printf("[DEBUG] the result of decoding the provided string is not valid UTF-8: %s", redactIfSensitive(sDec, strMarks))
return cty.UnknownVal(cty.String).WithMarks(strMarks), fmt.Errorf("the result of decoding the provided string is not valid UTF-8")
Copy link
Member

Choose a reason for hiding this comment

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

Do we have a precedent for returning the arguments' marks on an unknown value with an error? The unknown value from the error shouldn't need to propagate the marks any further, and I don't think we're returning marks in all cases 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.

Oh, good point! This was the precedent I cargo-culted:

return cty.UnknownVal(cty.DynamicPseudoType).WithMarks(markses...), fmt.Errorf(
"lookup failed to find '%s'", lookupKey)

But having poked around inside HCL for a bit I'm really pretty sure that the value is unused if we return an error from a function. I'll remove the marks.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

}

if fi.Mode().IsRegular() {
return cty.True, nil
return cty.True.WithMarks(pathMarks), nil
Copy link
Member

Choose a reason for hiding this comment

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

To me the marks on the input path seem logically distinct from the boolean existence of a file. While the input may clearly be sensitive, should using that cause the result to be sensitive? I guess it follows pretty closely to the fact that using the input in a conditional would cause the conditional result to retain the same marks, but just wanted to pose the question in case we don't really need cause the marks to propagate through here too.

Copy link
Member Author

Choose a reason for hiding this comment

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

The existing implementation (using the automatic re-marking from cty) does mark the result as sensitive:

$ tf console
> fileexists("main.tf")
false
> fileexists(sensitive("main.tf"))
(sensitive)

I don't think that's particularly useful, assuming that we don't intend the sensitive value implementation to protect against side-channel attacks. I'll plan to remove the marks from this function, but if anyone disagrees with that change I'm happy to leave them in.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is a small hazard here that someone was using nonsensitive(fileexists(...)) to achieve this effect before and would now need to remove the nonsensitive. I don't know how likely it is, but I mention it in case you think it might affect the risk/reward tradeoff.

Copy link
Member Author

Choose a reason for hiding this comment

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

That does make me more nervous about removing the marks. I hadn't thought of this situation where it breaks compatibility, no matter how unlikely it is. Given that we don't have any users requesting this change or considering it a bug, I'll leave it as-is for now.

Some function errors include values derived from arguments. This commit
is the result of a manual audit of these errors, which resulted in:

- Adding a helper function to redact sensitive values;
- Applying that helper function where errors include values derived from
  possibly-sensitive arguments;
- Cleaning up other errors which need not include those values, or were
  otherwise incorrect.
@alisdair alisdair force-pushed the alisdair/redact-sensitive-values-from-function-errors branch from 1b0c35a to 5d7cb81 Compare December 3, 2021 14:47
@alisdair alisdair requested a review from a team January 4, 2022 15:19
@alisdair alisdair added this to the v1.1.3 milestone Jan 4, 2022
@alisdair alisdair merged commit ef01d5d into main Jan 4, 2022
@alisdair alisdair deleted the alisdair/redact-sensitive-values-from-function-errors branch January 4, 2022 16:34
@github-actions
Copy link

github-actions bot commented Feb 4, 2022

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1.1-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

base64decode dumps sensitive values on error
3 participants