Skip to content

Commit

Permalink
Remove the environmental awareness feature (#16)
Browse files Browse the repository at this point in the history
* Revert "Add redaction control based on environment variables (#7)"

Due to the way cargo works .veil.toml can't impact other crates
consistently.

This reverts commit 69dd762.

* Remove all mentions of the environment aware feature

* Add a set_debug_format function

This is a simpler replacement for the environmental awareness feature.

* Mention being able to skip redacting data

* Move tests that disable redaction into a separate crate

This is neccessary because rust runs all tests in the same process,
leading to tests failing randomly, because of other tests modifying the
global state. There is some proposal on the rust compiler-team github
repo but until that gets stabilized we have to use this hack instead
rust-lang/compiler-team#508

* Loosen the version requirement of once_cell to 1.0.0

Co-authored-by: William <[email protected]>

* Hide the disable feature behind a feature flag

Ensure that the use of this feature requires a very explicit opt-in from
the user.

* Add support for disabling veil with VEIL_DISABLE_REDACTION

* Test the toggle feature with drone

* Minor fixes to disable-redaction-test

* Rename it to veil-tests-disable-redaction
* Set publish = false
* Change the outer line doc comment describing the test into a inner
  line doc comment

* Improve the disable veil redaction docs

This avoids repeating that the disable function needs the toggle feature
flag which makes it clearer that the VEIL_DISABLE_REDACTION envar also
needs the feature flag

* Clarify RedactionBehavior doc comment

Co-authored-by: William <[email protected]>

* Add missing space in README.md

* Update README.md

Make it clear that to skip redacting data the user needs to either call
the disable function *or* set the VEIL_DISABLE_REDACTION variable, not
both.

* Update outdated comment in the disable_redaction example

Co-authored-by: mae.kasza <[email protected]>
Co-authored-by: William <[email protected]>
  • Loading branch information
3 people authored Sep 26, 2022
1 parent 3e18f1f commit e2d8ffc
Show file tree
Hide file tree
Showing 28 changed files with 134 additions and 737 deletions.
7 changes: 3 additions & 4 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
kind: pipeline
--- kind: pipeline
name: default

platform:
Expand Down Expand Up @@ -36,7 +35,7 @@ steps:
- name: cargo-clippy-ci
image: rust:1.61
commands:
- cargo clippy -- -D warnings && cargo clippy --features environment-aware -- -D warnings
- cargo clippy -- -D warnings && cargo clippy --features toggle -- -D warnings
environment:
BUILD_ENV: dev
CARGO_HOME: /drone/src/.cargo
Expand All @@ -46,7 +45,7 @@ steps:
- name: cargo-test
image: rust:1.61
commands:
- cargo test --all && cargo test --all --features environment-aware
- cargo test --all && cargo test --all --features toggle
environment:
BUILD_ENV: dev
CARGO_HOME: /drone/src/.cargo
Expand Down
173 changes: 4 additions & 169 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 9 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@ license = "MIT"
repository = "https://github.com/primait/veil"

[workspace]
members = [
"veil-macros",
"veil-tests",
"veil-tests/environment-aware",
"veil-tests/environment-aware-fallback-on",
"veil-tests/environment-aware-fallback-off",
"veil-tests/environment-aware-fallback-panic",
"veil-tests/environment-aware-disable",
members = ["veil-macros", "veil-tests"
# Because those tests deal with global state we need to run them in a separate process.
# The easiest/only way to do this with the standard rust test harness is to put them in a
# separate crate
,"veil-tests/disable-redaction-test"
]

[features]
environment-aware = ["veil-macros/environment-aware", "lazy_static"]

[dependencies]
veil-macros = { path = "veil-macros" }
lazy_static = { version = "1", optional = true }
once_cell = "1"

[features]
toggle = []
41 changes: 5 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,39 +86,8 @@ enum InsuranceStatus {
}
```

# Environment Awareness

You can configure Veil to redact or skip redacting data based on environment variables. Enable the `environment-aware` Cargo feature like so in your Cargo.toml:

```toml
[dependencies]
veil = { version = "0.1", features = ["environment-aware"] }
```

## `VEIL_DISABLE_REDACTION`

Redaction can be completely disabled by setting the `VEIL_DISABLE_REDACTION` environment variable. This is only checked once during the program lifetime for security purposes.

## `.veil.toml`

Redaction can also be configured on a per-project basis using a `.veil.toml` file. Put this file in your crate or workspace root and Veil will read it at compile time.

**Please note, if you change the file, Veil won't see the changes until you do a clean build of your crate.**

### Example

`APP_ENV` is just an example here. You can match multiple environment variables with any UTF-8 name and value(s).

```toml
[env.APP_ENV]
redact = ["production", "staging"] # redact data if "APP_ENV" is set to any of these values
skip-redact = ["dev", "qa"] # SKIP redacting data if "APP_ENV" is set to any of these values

# If "APP_ENV" isn't set or isn't recognised...
[fallback]
redact = true # do redact data (default)
# OR
redact = false # don't redact data
# OR
redact = "panic" # panic at runtime
```
# Skip redacting data
In testing environments it may be useful not to censor your logs. You can globally disable Veil's redaction behavior at runtime by enabling the *non-default* feature flag `toggle` and:
- Setting the VEIL_DISABLE_REDACTION environment variable.
or
- Calling the `disable` function. See this [example](examples/disable_redaction.rs).
25 changes: 25 additions & 0 deletions examples/disable_redaction.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use std::env;
use veil::Redact;

#[derive(Redact)]
pub struct Customer {
#[redact(partial)]
first_name: String,
}

fn main() {
// If the environment variable APP_ENV is set to "dev" veil will not redact anything
if let Ok(env) = env::var("APP_ENV") {
if env == "dev" {
// Note that veil::disable needs the `toggle` feature flag enabled
veil::disable().unwrap();
}
}

println!(
"{:#?}",
Customer {
first_name: "John".to_string(),
}
);
}
Loading

0 comments on commit e2d8ffc

Please sign in to comment.