Skip to content

feat: redacting secrets in build logs. - #4311

Merged
vito merged 1 commit into
concourse:masterfrom
evanchaoli:redact-creds
Sep 9, 2019
Merged

vito merged 1 commit into
concourse:masterfrom
evanchaoli:redact-creds

Conversation

@evanchaoli

@evanchaoli evanchaoli commented Aug 22, 2019 •

Copy link
Copy Markdown
Contributor

I have done an initial version. But since the change is big, I would call for an initial review from design perspective first before I spend time on updating tests.

My testing pipeline is:

jobs:
- name: test-cred
  public: true
  plan:
  - task: run
    config:
      platform: linux
      image_resource:
        type: registry-image
        source: {repository: busybox}
      run:
        path: sh
        args:
         - -exc
         - |
           echo The name is ((localname))
           echo The password is ((test.pass)), and say ((hello))

Where ((test.pass)) and ((hello)) are defined in Vault.

Pipeline execution screen shot:
redact

Highlights of the design:

  • Tracks credential interpolation with VarsTracker, and makes it public.
  • Adds a BuildStepDelegate parameter to TaskConfigSource.FetchConfig, so that it can install a build log filter to delegate.
  • Redact credential with a filter function before output build logs in delegate.

Given not all users are sensitive with credential, and redact could lead to some performance drop, I'm thinking to add a CLI option to concourse web process to control if or not enable this redacting feature, by default, the switch will be off.

This PR will resolve issue #3972.

@vito Your comments are wanted.

@evanchaoli
evanchaoli requested review from a team August 22, 2019 17:54
@jamieklassen jamieklassen self-assigned this Aug 26, 2019

@vito vito left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great start! Thanks for waiting, I was on vacation. 🙂

I like the idea of tracking used vars and using them to know what to filter out. I wonder if we could apply it more generally than to just tasks? For example, a credential may go into task A and then propagate to task B through the filesystem instead of through vars. Maybe we could have one big var tracker for an entire build?

Following on that, maybe we could apply the same redacting to put/get steps? Ideally resource authors know not to print any sensitive information, but it may be better to be safe than sorry.

Comment thread atc/engine/builder/delegate_factory.go Resolved
Comment thread vars/template.go Resolved
@evanchaoli
evanchaoli force-pushed the redact-creds branch 2 times, most recently from 4ccde7e to cb9274c Compare September 5, 2019 05:37
@evanchaoli

evanchaoli commented Sep 5, 2019 •

Copy link
Copy Markdown
Contributor Author

Based on @vito 's comment, I enhanced the initial implementation. Highlights of the second implementation:

  • Add a CredVarsTracker struct that wraps credential manager, and tracks interpolated secrets.
  • Add a CredVarsTracker object in engineBuild struct, so that a build hold a single tracker.
  • Pass CredVarsTracker object to all build step delegate.
  • CredVarsTracker implements interface Variables, so that in get/put/task steps, step.delegate.GetCredVarsTracker() can be used as credential variables (original created by creds.NewVariables).
  • With all above changes, the build's CredVarsTracker object holds interpolated secrets from all build steps, thus redact build logs.
  • Add a command option --enable-redact-secrets to enable the feature. By default, it's off.

My test pipeline:

resource_types:
 - name: rt-tiny
   type: registry-image
   source:
     repository: evanli/tiny
     tag: v2
 
resources:
- name: tiny
  type: rt-tiny
  source:
   pass: ((test.pass))

jobs:
- name: test-cred
   public: true
   plan:
   - put: tiny
    params:
      key: ((hello))
 
   - task: task1
     config:
      platform: linux
      image_resource:
        type: registry-image
        source: {repository: busybox}
      outputs:
      - name: out
      run:
        path: sh
        args:
         - -exc
         - |
           echo The name is ((localname))
           echo The password is ((test.pass)), and say ((hello))
           echo ((hello)) > out/a.txt

   - task: task2
     config:
       platform: linux
       image_resource:
         type: registry-image
         source: {repository: busybox}
       inputs:
       - name: out
       run:
         path: sh
         args:
          - -exc
          - |
            cat out/a.txt

The resource tiny do nothing, just output source and params to build logs. And task1 passes a secret to task2 via file, then task2 print the secrets to build log. So that this pipeline has covered redacts build logs of get, put and task.

redact2

From the above screen shot, we can see all secrets have been redacted.

@vito For the chunky build log issue, as you said, it's tricky to solve, and need more discussion. I think that issue can be implemented with a separate PR. Given this PR changes a lot of files, rebasing the changes is a big pain. Given the feature is by default turned off, if you are ok with my current code, can we get this PR merged first? If you are ok with the current design and my suggestion about chunky problem, then I'm going to update unit tests and raise the final version of code change.

@vito

vito commented Sep 5, 2019

Copy link
Copy Markdown
Contributor

@vito For the chunky build log issue, as you said, it's tricky to solve, and need more discussion. I think that issue can be implemented with a separate PR. Given this PR changes a lot of files, rebasing the changes is a big pain. Given the feature is by default turned off, if you are ok with my current code, can we get this PR merged first? If you are ok with the current design and my suggestion about chunky problem, then I'm going to update unit tests and raise the final version of code change.

Totally fair. We can start small and iterate on it. 🙂 The new changes sound great, I'll try to review it today!

In the meantime, it looks like there are a couple build failures (I think fakes just need to be regenerated), and the DCO bot is unhappy: https://github.com/concourse/concourse/pull/4311/checks?check_run_id=212761804

Comment thread atc/engine/builder/delegate_factory.go Resolved
Comment thread atc/engine/builder/delegate_factory.go Resolved
Comment thread atc/engine/builder/step_factory.go Resolved
Comment thread atc/engine/engine.go Resolved
Comment thread atc/engine/builder/builder.go Resolved
Comment thread atc/exec/get_step.go Resolved
evanchaoli added a commit to evanchaoli/concourse that referenced this pull request Sep 6, 2019
With this change, for all secrets fetched from credential manager, if they appear
in build logs, then they will be automatically redacted as "[**redacted**]]".

As this is currently an exprimental feature, a "concourse web" command option
"--enable-redact-secrets" has been added to turn on this feature.

Close concourse#4311

Signed-off-by: Chao Li <[email protected]>
@evanchaoli evanchaoli changed the title WIP: initial code change of redacting secrets in build logs. For design review purpose. feat: redacting secrets in build logs. Sep 6, 2019
@evanchaoli
evanchaoli requested review from vito and removed request for a team September 6, 2019 05:45
Comment thread atc/engine/engine.go Resolved
Comment thread atc/engine/builder/delegate_factory.go Resolved
Comment thread atc/exec/get_step.go Resolved
Comment thread atc/exec/get_step_test.go Resolved
evanchaoli added a commit to evanchaoli/concourse that referenced this pull request Sep 9, 2019
With this change, for all secrets fetched from credential manager, if they appear
in build logs, then they will be automatically redacted as "[**redacted**]]".

As this is currently an exprimental feature, a "concourse web" command option
"--enable-redact-secrets" has been added to turn on this feature.

Close concourse#4311

Signed-off-by: Chao Li <[email protected]>
@evanchaoli
evanchaoli requested a review from vito September 9, 2019 03:05
@evanchaoli

Copy link
Copy Markdown
Contributor Author

With the lasted code I have just updated, the screen shot is:

redact3

evanchaoli added a commit to evanchaoli/concourse that referenced this pull request Sep 9, 2019
With this change, for all secrets fetched from credential manager, if they appear
in build logs, then they will be automatically redacted as "[**redacted**]]".

As this is currently an exprimental feature, a "concourse web" command option
"--enable-redact-secrets" has been added to turn on this feature.

Close concourse#4311

Signed-off-by: Chao Li <[email protected]>
evanchaoli added a commit to evanchaoli/concourse that referenced this pull request Sep 9, 2019
With this change, for all secrets fetched from credential manager, if they appear
in build logs, then they will be automatically redacted as "[**redacted**]]".

As this is currently an exprimental feature, a "concourse web" command option
"--enable-redact-secrets" has been added to turn on this feature.

Close concourse#4311

Signed-off-by: Chao Li <[email protected]>
evanchaoli added a commit to evanchaoli/concourse that referenced this pull request Sep 9, 2019
With this change, for all secrets fetched from credential manager, if they appear
in build logs, then they will be automatically redacted as "[**redacted**]]".

As this is currently an exprimental feature, a "concourse web" command option
"--enable-redact-secrets" has been added to turn on this feature.

Close concourse#4311

Signed-off-by: Chao Li <[email protected]>
evanchaoli added a commit to evanchaoli/concourse that referenced this pull request Sep 9, 2019
With this change, for all secrets fetched from credential manager, if they appear
in build logs, then they will be automatically redacted as "[**redacted**]]".

As this is currently an exprimental feature, a "concourse web" command option
"--enable-redact-secrets" has been added to turn on this feature.

Close concourse#4311

Signed-off-by: Chao Li <[email protected]>
With this change, for all secrets fetched from credential manager, if they appear
in build logs, then they will be automatically redacted as "[**redacted**]]".

As this is currently an exprimental feature, a "concourse web" command option
"--enable-redact-secrets" has been added to turn on this feature.

Close concourse#4311

Signed-off-by: Chao Li <[email protected]>

@vito vito left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I noticed a tiny thing to clean up but everything else looks good so I'll just merge and fix it myself to save another review cycle. 🙂

Thanks!

I've opened #4389 to keep track of the problem with chunked secrets. We can address it some time in the future. I'm thinking it might be a requirement for removing the feature flag and making it the default.

writtenBytes, writeErr = writer.Write([]byte("ok super-secret-source ok"))
})

It("should be redacted", func() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 Nice! These tests feel pretty descriptive and high-level.

Comment thread atc/engine/engine.go
type engine struct {
builder StepBuilder
builder StepBuilder
secrets creds.Secrets

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this can be rolled back now that the StepBuilder has them

Comment thread atc/exec/check_step.go
plan atc.CheckPlan
metadata StepMetadata
containerMetadata db.ContainerMetadata
secrets creds.Secrets

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like this never needed to be here, thanks for cleaning it up!

@vito vito closed this in ebc23a7 Sep 9, 2019
@vito
vito merged commit ebc23a7 into concourse:master Sep 9, 2019
@jamieklassen jamieklassen added this to the v5.6.0 milestone Sep 11, 2019
vito added a commit that referenced this pull request Sep 11, 2019
ref. #4311 and #4387

Signed-off-by: Alex Suraci <[email protected]>
vito added a commit that referenced this pull request Sep 11, 2019
ref. #4311 and #4387

Signed-off-by: Alex Suraci <[email protected]>
@jamieklassen jamieklassen added the release/documented Documentation and release notes have been updated. label Sep 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release/documented Documentation and release notes have been updated.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants