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

Creds-init writes to fixed location when HOME override is disabled #2180

Merged
merged 1 commit into from Mar 24, 2020
Merged

Creds-init writes to fixed location when HOME override is disabled #2180

merged 1 commit into from Mar 24, 2020

Conversation

ghost
Copy link

@ghost ghost commented Mar 6, 2020

Changes

Fixes #2165
Relates to #2013

When the disable-home-env-overwrite flag is set to "true" each Step in a Task can conceivably have its own HOME directory. The concept of "HOME" is further muddied in systems that randomize the UID of containers.

When the disanle-home-env-overwite flag is set to "true", creds-init will write its credentials to /tekton/creds instead of /tekton/home. Then the entrypoint binary will copy the credentials from /tekton/creds into $HOME before the Task's Steps are allowed to run. This change should be completely transparent to the user.

For those users who were for some very specific reason actually relying on the credentials being in /tekton/home we'll now expose a new variable substitution: $(credentials.path) will get replaced with the directory that creds-init writes to - either /tekton/home or /tekton/creds depending on the state of the disable-home-env-overwrite flag.

This is a stop-gap measure as we work towards beta. It seems that we will probably need to revisit our recommendations around auth and the contract we're making with creds-init.

  • Variable replacement for $(credentials.path)

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

See the contribution guide for more details.

Double check this list of stuff that's easy to miss:

Reviewer Notes

If API changes are included, additive changes must be approved by at least two OWNERS and backwards incompatible changes must be approved by more than 50% of the OWNERS, and they must first be added in a backwards compatible way.

Release Notes

Users who disable Tekton's HOME env overwrite will now find that git and docker credentials are written to a volumeMount, /tekton/creds, before they're copied into $HOME by the entrypoint. A new variable replacement has been introduced, $(credentials.path), which expands to the directory where creds-init writes its credentials, either /tekton/home or /tekton/creds.

@googlebot googlebot added the cla: yes Trying to make the CLA bot happy with ppl from different companies work on one commit label Mar 6, 2020
@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 6, 2020
@ghost
Copy link
Author

ghost commented Mar 6, 2020

/hold

Want to look at this again with fresh eyes on Monday before committing.

@tekton-robot tekton-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 6, 2020
@ghost ghost added the needs-cherry-pick Indicates a PR needs to be cherry-pick to a release branch label Mar 6, 2020
docs/auth.md Outdated
@@ -24,6 +24,12 @@ To solve this, before any `PipelineResources` are retrieved, all `pods` execute
a credential initialization process that accesses each of its secrets and
aggregates them into their respective files in `$HOME`.

Please note: If the `disable-home-env-overwrite` feature flag has been set to
Copy link
Member

Choose a reason for hiding this comment

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

So, in the case of disable-home-env-overwrite (and by default in the future), do we decide that /tekton/home is where we write anything that "would be in $HOME" ? (like .gitconfig, …) I am +:100: on this as we will document it, and we are sure it's always written at the same place.

Copy link
Author

Choose a reason for hiding this comment

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

Interesting idea! I think this might make sense. I was considering using a more explicit name like /tekton/creds since we'd originally planned for /tekton/home to be removed in future. But if we see this as reusable then I think it makes sense to leave it as-is.

I'm going to write up a one-page design doc and will present it to the WG on wednesday just to quickly get community feedback on that plan.

Copy link
Author

Choose a reason for hiding this comment

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

We should probably also expose this as a variable so that users don't have to hard-code it.

Copy link
Member

Choose a reason for hiding this comment

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

+:100: on both your comments :wink: I really like /tekton/creds and having a variable for it is 😻

Copy link
Author

Choose a reason for hiding this comment

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

👍 awesome, i've implemented both of these now.

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 9, 2020
@ghost
Copy link
Author

ghost commented Mar 9, 2020

I've written up a very short design doc covering the solution in this PR and a slight alternative. Doc here: https://docs.google.com/document/d/1SVuDt-SXPHymz41dveSXFSPrx5Z-Wzb9eHliJAyYg4o

@ghost
Copy link
Author

ghost commented Mar 10, 2020

Note to self: This would probably break PipelineResources when the disable-home-env-overwrite flag is enabled (and eventually flipped to on by default in the following release). Might need to update PipelineResources to account for this.

This didn't end up being true because the entrypoint now copies the creds into $HOME. So the behaviour is the same regardless of the state of the flag: credentials from a Secret will end up in the PipelineResource container's $HOME dir.

@ghost
Copy link
Author

ghost commented Mar 21, 2020

I've added variable replacement from $(credentials.path) to /tekton/home or /tekton/creds depending on what the disable-home-env-overwrite flag is set to.

I've updated the git PipelineResource to deal with the possibility that creds are in /tekton/creds instead of /tekton/home.

@ghost
Copy link
Author

ghost commented Mar 22, 2020

This change should be pretty much invisible to users now, no extra copying in their Steps should be necessary. The entrypoint binary now copies the creds into $HOME instead of creds-init (when the disable-home-env-overwrite feature flag is true) so the net result is the same regardless of the feature flag: creds end up in container HOME dirs.

@ghost
Copy link
Author

ghost commented Mar 22, 2020

/hold cancel

I think this is probably ready for review now.

@tekton-robot tekton-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 22, 2020
Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

Looks good, just a small question

cmd/entrypoint/main.go Show resolved Hide resolved
@@ -125,6 +125,15 @@ func ApplyTaskResults(spec *v1alpha1.TaskSpec) *v1alpha1.TaskSpec {
return ApplyReplacements(spec, stringReplacements, map[string][]string{})
}

// ApplyCredentialsPath applies a substitution of the key $(credentials.path) with the path that the creds-init
// helper will write its credentials to.
func ApplyCredentialsPath(spec *v1alpha1.TaskSpec, path string) *v1alpha1.TaskSpec {
Copy link
Member

Choose a reason for hiding this comment

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

Is this only usable as internal ? (because I think it's gonna be invalid if using directly in a spec)

Copy link
Author

Choose a reason for hiding this comment

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

Could you tell me more about it being invalid if used directly in spec? It's intended for users to be able to work with as well.

Copy link
Member

Choose a reason for hiding this comment

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

I think this might fail at validation saying credential.path is an invalid variable (not 100% sure but my feeling is that not having anything about it in the validation code means it will fail — maybe I am wrong though, a tests showing this would be nice 😝 )

Copy link
Author

Choose a reason for hiding this comment

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

Aaaaah. Lemme check. Great catch.

Copy link
Author

Choose a reason for hiding this comment

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

Initial manual test proved positive - I was able to use $(credential.path) in a TaskRun w/ embedded TaskSpec. I didn't hit a validation error and the Task ran successfully.

I'm going to add a test for this right now to make sure it doesn't fail validation in future.

Copy link
Author

Choose a reason for hiding this comment

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

Updated with tests for task and taskrun validations in both v1beta1 and v1alpha1 packages.

@tekton-robot tekton-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 23, 2020
When the disable-home-env-overwrite flag is set to "true" each Step in a
Task can conceivably have its own HOME directory. The concept of "HOME"
is further muddied in systems that randomize the UID of containers.

So now creds-init will write to a shared volumeMount, /tekton/creds,
when the disable-home-env-overwrite flag is "true". When the flag is
"false" creds-init will behave exactly the same as before, writing the
credentials to /tekton/home, and no extra volume mount will be needed.

This change should be mostly transparent to users: the entrypoint
binary in each Step will now try and copy credentials out of
/tekton/creds into $HOME/. The net result is the same as before the
flag was introduced, it's just that entrypoint does the final copy into
$HOME instead of creds-init.

To support users who were in some way depending on the location of
credentials, the path to where creds-init writes is now exposed for Tasks
via the $(credentials.path) variable. This will be replaced with the
directory that creds-init writes to: either "/tekton/home" or "/tekton/creds"
depending on the state of the disable-home-env-overwrite flag.
Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

/lgtm
/meow

@tekton-robot
Copy link
Collaborator

@vdemeester: cat image

In response to this:

/lgtm
/meow

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 24, 2020
@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vdemeester

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@vdemeester
Copy link
Member

/test pull-tekton-pipeline-integration-tests

1 similar comment
@vdemeester
Copy link
Member

/test pull-tekton-pipeline-integration-tests

@vdemeester
Copy link
Member

/test pull-tekton-pipeline-build-tests

@tekton-robot tekton-robot merged commit 1325eea into tektoncd:master Mar 24, 2020
@ghost ghost removed the needs-cherry-pick Indicates a PR needs to be cherry-pick to a release branch label Mar 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cla: yes Trying to make the CLA bot happy with ppl from different companies work on one commit lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TaskRun fails during initialization when disable-home-env-overwrite=true
3 participants