Skip to content

feat(atc): support var_sources in pipeline. - #4600

Merged
vito merged 8 commits into
concourse:masterfrom
evanchaoli:multi-cred
Nov 13, 2019
Merged

vito merged 8 commits into
concourse:masterfrom
evanchaoli:multi-cred

Conversation

@evanchaoli

@evanchaoli evanchaoli commented Oct 14, 2019 •

Copy link
Copy Markdown
Contributor

Resolve #4579

This is for initial review from design perspective.

Highlights of the changes:

  1. Add "credential_managers" in pipeline YAML, atc/config.go
  2. Valid credential manager's configure in atc/validate.go. Also to solve cyclic imports, moved validate.go to atc/configvalidate/validate.go.
  3. Add a new field credential_managers in table pipelines. fly set-pipeline will store pipeline credential managers to this new field.
  4. Add a new field credential_managers in table builds. When create new build, get the value from pipeline.
  5. In atc/engine/builder.go, create pipeline secrets variables, put them and global secrets into a MultiVars, so that build steps can interpolate secrets from pipeline credential managers as well as the global credential manager.
  6. Add a new function to interface creds.Manager. When a build finishes, call this method to cleanup pipeline credential managers, basically, stop the reauther go routine.

Note: Tests have not been updated yet.

Contributor Checklist

Are the following items included as part of this PR? Please delete checkbox items that don't apply.

Reviewer Checklist

This section is intended for the core maintainers only, to track review progress. Please do not
fill out this section.

  • Code reviewed
  • Tests reviewed
  • Documentation reviewed
  • Release notes reviewed
  • PR acceptance performed

@evanchaoli
evanchaoli requested review from a team October 14, 2019 10:00
@vito

vito commented Oct 16, 2019

Copy link
Copy Markdown
Contributor

Hey thanks for picking this up! 🙂 Hoping to get to this soon and submit some feedback. I've got a few loose-ends to tidy up in in this area, so I'm going to address them beforehand just to make sure my head's in the right place with regard to the long-term vision:

  1. RFC: team credential managers rfcs#21 which is likely to be superceded by...
  2. RFC: Projects rfcs#32 which introduces project-level credential manager config (as vars_sources:)

Once I have this all cleaned up I'll come back and cross-reference your proposal with mine and make sure there's common ground and a clear path forward to the long-term roadmap. 🙂

My tentative thoughts are that it's fine to introduce them at the pipeline-level first since projects will take a while to get here, and starting with pipeline-level creds will at least get us away from a single global credential manager.

I'd also be excited to use this as a cheaper way of testing credential management. Perhaps in combination with #4502 we can even add a testflight test and/or start to test Vault and other integrations more cheaply (now that they can be tested independent of the cluster's configuration).

Thanks again! I'll try to get to this soon.

@evanchaoli
evanchaoli force-pushed the multi-cred branch 2 times, most recently from 8c47a95 to fd0ba98 Compare October 16, 2019 19:29
@evanchaoli

evanchaoli commented Oct 16, 2019 •

Copy link
Copy Markdown
Contributor Author

I use two vaults in my test:

  • http://<local-ip>:7200 is configured to concourse web
  • http://<local-ip>:8200 is configured in pipeline yaml

Pipeline:

credential_managers:
- name: dev-vault
  type: vault
  config:
    url: http://192.168.205.77:8200
    path_prefix: concourse
    client_token: ((my-vault-token))

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

The pipeline Vault's config takes a variable ((my-vaule-token)), that will be interpolated from atc's vault, and the task takes a variable ((test.pass)), that will be from the pipeline vault.

The screen shots of my test result is simple, but it proves the change has been working:

test-multiple-vaults

@vito

vito commented Oct 16, 2019

Copy link
Copy Markdown
Contributor

The pipeline Vault's config takes a variable ((my-vaule-token)), that will be interpolated from atc's vault, and the task takes a variable ((test.pass)), that will be from the pipeline vault.

Hah, that's pretty cool. I was wondering about this part because these pipeline-level vars would otherwise need to be directly embedded (scary even with encryption). So with this it's sort of like having a hierarchy of credential management. 🤔 An interesting pattern. Up until now I've been hoping to remove the global credential manager, but I guess this would be one reason to keep it around.

@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.

Haven't had time to complete this review yet but I'll submit what I have so far. 🙂 This is a great start!

tl;dr of my broader feedback:

  • I'm thinking of calling this var_sources: instead of credential_managers:
  • For concourse/rfcs#32 and concourse/rfcs#21 I had concerns over how many credential managers we'd be keeping around at runtime, now that they're dynamic, and those concerns carry over here. Maybe we could have a centralized object that maintains a single instance of each pipeline's credential manager stack?
  • The handling of the YAML/JSON config in addition to the flags is a little awkward. In the long run I'd like to find a broader solution to this, but in the meantime maybe you could check out how skymarshal handles this?
  • We'll probably need to encrypt the credential manager config in the database, since it won't always have the cred manager's creds interpolated from the global cred manager.
  • I'm not sure if we need to store cred managers per-build, especially if we decide that maintaining single instances per-pipeline is feasible.

Thanks again for tackling this! It's a pretty big feature. To be honest it might warrant an RFC but I think it's fine to keep going here as a proof-of-concept for now. I don't see there being a whole lot of pushback on an RFC anyway.

Comment thread atc/api/configserver/save.go Resolved
Comment thread atc/api/configserver/get.go Resolved
Comment thread atc/configvalidate/validate.go Resolved
Comment thread atc/creds/vault/manager.go Resolved
Comment thread atc/creds/vault/manager.go Resolved
Comment thread atc/creds/vault/manager.go Resolved
Comment thread atc/db/build.go Resolved
Comment thread atc/db/build.go Resolved
@@ -0,0 +1,4 @@
BEGIN;
ALTER TABLE pipelines ADD COLUMN credential_managers json;

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.

If we're encrypting this column it can't be JSON, fwiw. And I think we'll have to, since I don't think we can rely on interpolating creds from the outer (global) cred manager.

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.

Can we actually make credential_managers its own table? We could probably model them very similarly to resources.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@pivotal-jwinters Thanks for the comment. I considered that at the beginning, and I decided to begin with a simple way as this doesn't impact big picture design of this feature. So I'd defer this change till other design parts get clear.

Comment thread atc/engine/builder/builder.go Resolved
@@ -0,0 +1,4 @@
BEGIN;
ALTER TABLE pipelines ADD COLUMN credential_managers json;

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.

Can we actually make credential_managers its own table? We could probably model them very similarly to resources.

@evanchaoli

Copy link
Copy Markdown
Contributor Author

@vito I have just pushed a new version, and resolved some review comments.

@evanchaoli
evanchaoli force-pushed the multi-cred branch 3 times, most recently from 4e451c1 to 5b2fc7c Compare October 18, 2019 21:04
@evanchaoli

Copy link
Copy Markdown
Contributor Author

@vito I just pushed a new commit. Highlights of this new commit:

  • Add VarSourcePool in atc/creds/pool.go. It maintains a map of credential managers by config. So that if multiple pipelines configure same Vault, then only one Vault instance will be created.
  • VarSourcePool is a runner. It periodically check lastUseTime of all managers. If a manager is not used for certain time (I hard code 5 minutes now, we can make it configurable), it will be closed and deleted from the map.
  • Add Variables() to struct Pipeline, so that var_sources is handled at pipeline level.
  • Make check of both lidar and non-lidar work now.
  • Add interface PipelineRef in atc/db/pipeline_ref.go in order to avoid duplicate code of pipeline reference in many structures.

In this version, I might not clean up code perfectly. The code may contain some commented lines, "EVAN" in logs, etc. Please ignore those nits. I'll clean up and squash later.

@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.

Haha, well I started reviewing but then noticed the meatier parts to review haven't been checked in. So this is mostly nitpicks and questions.

Comment thread atc/db/check_factory.go Resolved
Comment thread atc/db/pipeline.go Resolved
Comment thread atc/db/pipeline.go Resolved
Comment thread atc/db/team.go Resolved
Comment thread atc/engine/builder/builder.go Resolved
Comment thread atc/radar/resource_type_scanner.go Resolved
Comment thread atc/radar/resource_type_scanner.go Resolved
Comment thread atc/utils/stringencrypt.go Resolved
Comment thread atc/db/build.go Resolved
Comment thread atc/atccmd/command.go Resolved
@evanchaoli
evanchaoli force-pushed the multi-cred branch 2 times, most recently from 14d47ec to 374337f Compare October 23, 2019 23:07
@evanchaoli

Copy link
Copy Markdown
Contributor Author

@vito Really sorry for missing to check in the two new files, I always forget git add new files. (: I just quickly cleaned up some nit comments, and added the two missing files. I will address rest of comments soon.

@jamieklassen

Copy link
Copy Markdown

I was just perusing old PRs and saw one that reminded me of this work. I might have misunderstood the core concepts here, but if this gets merged, might it unblock #3081?

@evanchaoli
evanchaoli force-pushed the multi-cred branch 2 times, most recently from 5e340a6 to 663bdd5 Compare October 24, 2019 13:29
@evanchaoli

Copy link
Copy Markdown
Contributor Author

@vito I just pushed again and addressed all of comments including data encryption and NewInstance(map[string]interface{} issues. I should have pushed last night, but unfortunately the hotel's wifi seems to block github.com, thus I came to office this morning and got the code pushed.

@evanchaoli

Copy link
Copy Markdown
Contributor Author

I was just perusing old PRs and saw one that reminded me of this work. I might have misunderstood the core concepts here, but if this gets merged, might it unblock #3081?

I think this PR will unblock #3081. Once this PR is merged, user may define credential in pipeline, but #3081 still needs to add key-vault as a credential manager.

@evanchaoli
evanchaoli force-pushed the multi-cred branch 2 times, most recently from 45d7b7c to 450bbf8 Compare October 30, 2019 03:44
@vito

vito commented Oct 30, 2019 •

Copy link
Copy Markdown
Contributor

@evanchaoli Taking another look at this today! One quick request: would you mind making subsequent changes as new commits instead of force-pushing? It'll just make it a bit easier for me to tell what's new when re-reviewing. For example I'm wondering what this allowRootPath var is since that seems new from the last change set. Having fine-grained commits with reasoning included will also make the history a bit easier to peruse instead of just one big-bang commit with everything. Thanks!

@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.

Looking good! Leaving some early reviews before I try things out by hand. I'm going to try getting the dummy credential manager working and use that for testing things out locally.

edit: I especially like the pipelineRef idea - thanks for that refactor!

Comment thread atc/creds/credhub/credhub.go Resolved
Comment thread atc/creds/dummy/manager_factory.go Resolved
Comment thread atc/creds/pool.go Resolved
Comment thread atc/creds/pool.go Resolved
Comment thread atc/creds/pool.go Resolved
Comment thread atc/creds/pool.go Resolved
Comment thread atc/creds/dummy/manager_factory.go Resolved
Comment thread atc/engine/builder/builder.go Resolved
Comment thread atc/db/pipeline_ref.go Resolved
@vito

vito commented Oct 30, 2019

Copy link
Copy Markdown
Contributor

I got the dummy credential manager working and wrote a testflight test using it - here's a PR to your fork: evanchaoli#1 - theoretically if that's merged it'll propagate to this PR too.

@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 to see all the tests passing! At this point I only have minor things to comment on, so I think we're pretty close to mergeable. I'm going to preemptively approve since the value in getting this merged outweighs my pretty minor nitpicks.

I yield the floor to @concourse/core-api for further review. 🙂

Comment thread atc/atccmd/command.go Resolved
Comment thread atc/api/resourceserver/check_webhook.go Resolved
Comment thread atc/creds/pool_test.go Resolved
Comment thread atc/db/check_factory.go Resolved
Comment thread atc/engine/builder/builder.go Resolved
Comment thread atc/radar/resource_scanner.go Resolved
Comment thread atc/radar/resource_type_scanner.go Resolved
Comment thread atc/config.go
}

type VarSourceConfig struct {
Name string `json:"name"`

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.

Actually, is this name used anywhere?

It seems like it would make sense to be able to explicitly reference the var source to fetch from, e.g. ((myvault:foo/bar.baz)). But I don't think that's been implemented.

I think we should either implement that or remove the field for now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

((myvault:foo/bar.baz)) is exactly what one of our users asked to me when I demoed this feature to him. I plan to implement that with a separate PR as I want to make this feature work first, and don't want this PR to grow any further. :)

@jwntrs jwntrs Nov 8, 2019 •

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.

@evanchaoli is there a strong use case for wanting to cycle through all cred managers? It seems like we could get into some weird behaviour if someone added a new cred manager which unknowingly overrides a value from another one. And they wouldn't know it until it was already running in the pipeline.

I know it adds more to this PR, but I would be in favour of referencing cred managers by name as being the only supported method. It's much more in line with how resources work, and the direction we want to take with re-usable resources/tasks in projects.

@evanchaoli evanchaoli Nov 8, 2019 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@pivotal-jwinters I don't have a strong use case right now. One use case I can image is, it would be helpful for pipeline debugging. Like when debugging the pipeline, user may add a dummy var source in the first place, which might 1) make sure all vars can be interpolated; or 2) pin some vars to certain values.

The other point is that, I don't think much user would add more than one var_source to a pipeline. Practically, maintaining a Vault is not easy given the serious security matter. So I don't think cycle through all var sources would bring serious issue. Only when users start to use the feature, then we know if that's really an issue.

To support ((myvault:foo/bar.baz)) syntax, some more changes are needed, because with current code, var_source name is not tracked by creds.Secrets. Again, I don't want to make this PR any bigger, it has been functional, and should fit most of use cases.

As our communication has long delay due to time difference, I just thought over, if you strongly insist to support var source name, a quick trade-off I can do is, to restrict only the first var_source defined in pipeline will be used. This trade-off would 1) eliminate the "cycle through" concern, 2) not impact our use case because our use will mostly add only one var_source to a pipeline, 3) still support the debugging use case as I described above.

To summarize, I still suggest merge this PR first. If you are strongly against that, I can do the trade-off. Once this PR is merged, I commit to contribute a PR to support ((myvault:foo/bar.baz)) syntax.

@jwntrs jwntrs Nov 11, 2019 •

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.

@evanchaoli I understand that it's functional and that it meets all your use cases, however if we introduce named credential managers later on, it will be a breaking change. However since this is going to be an experimental/undocumented feature maybe that's ok. I think as long as we get to the point where named credential managers are the only supported method before we remove the experimental tag, then I would be ok merging this as is.

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.

👍 to merging for now and requiring named var references later - I'm working that aspect into my RFC. 🙂

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@pivotal-jwinters Thanks for understanding. I'm absolutely fine with only removing the experimental tag after named syntax is supported. :) But to clarify, the next PR, for named var source, would NOT be a breaking change. The behavior I'm planning to implement is like:

  • ((var1)): iterate over all var_sources including the system level credential manager to look for var1
  • ((name1:var1)): only look up var source name1 for var1.
  • ((name1,[name2,...]:var1)): only look up the multiple specified var sources for var1.
  • ((sys:var1)): only look up the system level credential manager for var1
  • ((name1,[name2,...,]sys:var1)): only look up specified var sources as well as the system level credential manager for var1.

which would leave the flexibility to users.

Anyway, please merge this PR first. If you have different opinion with the design, we may discuss in a new issue. Once this PR is merged, I'll create an issue to track the named var source change, and we may discuss the design over there.

@vito

vito commented Nov 7, 2019

Copy link
Copy Markdown
Contributor

Actually now I'm wondering if we should go through the RFC process for this. 🤔 There was a lot of nuance captured in concourse/rfcs#21 and its comments, and it's adding pretty significant functionality to pipelines, which is typically what the RFC process is for.

I'm already going to have to wrap up all of our RFCs for v10 now that you've lit a fire under my ass with #4708 lol. I can write up a new RFC based on the team credential managers RFC, and have it reflect my understanding of this PR and maybe bring up some of the concerns/ideas from concourse/rfcs#21 so we can agree on the next steps to take after this is merged.

I don't want your branch to set around forever and go stale in the meantime so I'm OK with merging this anyway and having it exist as an experimental or undocumented feature until the RFC process completes, as long as we're sure it won't cause any issues.

@evanchaoli

evanchaoli commented Nov 8, 2019 •

Copy link
Copy Markdown
Contributor Author

I don't want your branch to set around forever and go stale in the meantime so I'm OK with merging this anyway and having it exist as an experimental or undocumented feature until the RFC process completes, as long as we're sure it won't cause any issues.

@vito Thanks for understanding. I'm absolutely fine to have it as an experimental or undocumented feature for a while.

@evanchaoli
evanchaoli force-pushed the multi-cred branch 2 times, most recently from e3e171e to fb33bd5 Compare November 8, 2019 06:33

@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.

@pivotal-jwinters Would you mind approving or dismissing your review? I think we're good to merge at this point and start working on the next step.

@evanchaoli I'll have an RFC up soon that covers ((var)) semantics with regard to var_sources - so I would recommend holding off on further work until we can align on how that should behave. 🙂 Feel free to start anyway, but e.g. I'm currently thinking we should just enforce named var usage for var_sources and have ((foo)) only query the global credential manager and support ((name:foo)) for var_sources. We can discuss this further in the RFC once I have a draft up.

As there is more work to be done after this PR is merged I've started updating our 'Credentials Redux' project to keep track of it:

https://github.com/concourse/concourse/projects/31

I'm not entirely sure if you'll be able to move cards around and such (you currently have Triage contributor level but I'm not sure if that allows you to interact with projects), but I just wanted to start keeping track of this somewhere on our roadmap.

@vito vito changed the title feat(atc): support credential_managers in pipeline. feat(atc): support var_sources in pipeline. Nov 12, 2019
@evanchaoli

Copy link
Copy Markdown
Contributor Author

@evanchaoli I'll have an RFC up soon that covers ((var)) semantics with regard to var_sources - so I would recommend holding off on further work until we can align on how that should behave. 🙂 Feel free to start anyway, but e.g. I'm currently thinking we should just enforce named var usage for var_sources and have ((foo)) only query the global credential manager and support ((name:foo)) for var_sources. We can discuss this further in the RFC once I have a draft up.

@vito Sure, I'll only start next step implementation after we align on the design. Do we need to open an issue and discuss design in the issue?

BTW, I just tried, unfortunately, I'm not able to move cards on project.

@evanchaoli evanchaoli mentioned this pull request Nov 13, 2019
10 tasks
@vito

vito commented Nov 13, 2019

Copy link
Copy Markdown
Contributor

@vito Sure, I'll only start next step implementation after we align on the design. Do we need to open an issue and discuss design in the issue?

I'm going to either submit a new RFC or adapt concourse/rfcs#21 to it. Going to try and get something up today. I'll comment here when it's up!

@vito
vito merged commit 638509f into concourse:master Nov 13, 2019
@vito

vito commented Nov 13, 2019

Copy link
Copy Markdown
Contributor

@evanchaoli submitted a draft here: concourse/rfcs#39

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support pipeline level credential manager

4 participants