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

Add Step and Sidecar Workspaces feature #3700

Merged
merged 1 commit into from May 5, 2021
Merged

Add Step and Sidecar Workspaces feature #3700

merged 1 commit into from May 5, 2021

Conversation

ghost
Copy link

@ghost ghost commented Jan 20, 2021

Changes

TEP: https://github.com/tektoncd/community/blob/master/teps/0029-step-workspaces.md
Fixes #2343

Access to Workspaces can now be limited to specific Steps and Sidecars in a Task.
This allows Task authors to isolate sensitive data to specific images, reducing
exposure of assets like credentials.

As a side-effect of this change Workspaces are now mounted to Sidecars by
default, just as they are to Steps.

Submitter Checklist

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

  • Includes tests (if functionality changed/added)
  • Includes docs (if user facing)
  • Commit messages follow commit message best practices
  • Release notes block has been filled in or deleted (only if no user facing changes)

Release Notes

- New alpha feature added: "Step and Sidecar Workspaces"
    - Requires "enable-api-fields: alpha" feature gate.
    - Sidecars in a Task now receive Workspaces, just like Steps do.
    - Steps and Sidecars can now specify which Workspaces they want access to. This isolates the workspace to only those Steps or Sidecars that need them, allowing Task authors to limit exposure of sensitive data like credentials.
    - The default behaviour for workspaces in Steps remains the same - all Steps get access to them.

@ghost ghost added the kind/feature Categorizes issue or PR as related to a new feature. label Jan 20, 2021
@tekton-robot tekton-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Jan 20, 2021
@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jan 20, 2021
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/workspace/apply.go 94.6% 91.3% -3.3

@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 Jan 20, 2021
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/workspace/apply.go 94.6% 97.1% 2.5

@ghost
Copy link
Author

ghost commented Jan 20, 2021

Build tests are failing with following message:

/home/prow/go/src/github.com/tektoncd/pipeline is out of date. Please run hack/update-codegen.sh

But update-codegen.sh doesn't create any new code when I run it. This error is actually appearing because update-openapigen.sh needs to be run. I'm going to update that error message as part of this PR.

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/workspace/apply.go 94.6% 97.1% 2.5

@ghost ghost added this to the Pipelines 0.21 milestone Jan 25, 2021
@bobcatfish bobcatfish self-assigned this Feb 2, 2021
Copy link
Collaborator

@bobcatfish bobcatfish left a comment

Choose a reason for hiding this comment

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

Started with some initial comments on docs and examples, all super minor so far! Will return to review more ASAP

docs/workspaces.md Show resolved Hide resolved
# Note: must explicitly include volumeMount for the workspace to be accessible in the Sidecar
volumeMounts:
- name: $(workspaces.signals.volume)
mountPath: $(workspaces.signals.path)
Copy link
Collaborator

Choose a reason for hiding this comment

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

ahhh its so much better now :D

docs/workspaces.md Show resolved Hide resolved
# Note: must explicitly add volumeMount to gain access to Workspace in sidecar
volumeMounts:
- name: $(workspaces.signals.volume)
mountPath: $(workspaces.signals.path)
Copy link
Collaborator

Choose a reason for hiding this comment

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

niiiiice

script: |
#!/usr/bin/env ash
if [ -f "$(workspaces.signals.path)"/start ] ; then
echo "This step should not have access to the signals workspace."
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍 👍 👍

metadata:
generateName: workspace-isolation-
spec:
timeout: 2m0s
Copy link
Collaborator

Choose a reason for hiding this comment

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

oooo is this here b/c of the loop in the sidecar? might be worth adding a couple comments (e.g. in the sidecar loop), i had to work through that myself and was about to say "we should add a timeout"

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 comments in both loops mentioning the use of timeout to prevent looping forever.

hack/verify-codegen.sh Show resolved Hide resolved
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/workspace/apply.go 94.6% 97.1% 2.5

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/workspace/apply.go 94.6% 97.1% 2.5

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/workspace/apply.go 94.6% 97.1% 2.5

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/workspace/apply.go 94.6% 97.1% 2.5

Copy link
Collaborator

@bobcatfish bobcatfish left a comment

Choose a reason for hiding this comment

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

I think pretty much all my comments are just idle thoughts or unimportant nitpicks! The only at all "significant" comment I have is a think there might be a bit of missing test coverage on the mount path overriding.

Looks great!

/approve

i wonder if we want to explicitly do anything about how this impacts pipelineresources? since this was implemented using steptemplates, removing the volumes from the step template would also mean removing it from pipelineresources, but right now we don't cover it with any tests or mention it in docs - i think its probably better this way; its hard to imagine any pipelineresources that would be impacted, probably no one even knew that was happening, and lastly we probably want to discourage using pipelineresources anyway, but i wanted to bring it up and see what you think

@@ -217,13 +217,14 @@ While iterating on the project, you may need to:
1. Verify it's working by [looking at the logs](#accessing-logs)
1. Update your (external) dependencies with: `./hack/update-deps.sh`.
1. Update your type definitions with: `./hack/update-codegen.sh`.
1. Update your OpenAPI specs with: `./hack/update-openapigen.sh`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

thanks @sbwsg 🙏

pkg/apis/pipeline/v1beta1/workspace_types.go Outdated Show resolved Hide resolved
docs/workspaces.md Outdated Show resolved Hide resolved
pkg/workspace/apply_test.go Outdated Show resolved Hide resolved
Workspaces: []v1beta1.WorkspaceDeclaration{{
Name: "source",
}},
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice, clear test cases!

pkg/workspace/apply.go Show resolved Hide resolved
pkg/reconciler/taskrun/resources/apply.go Show resolved Hide resolved
@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 4, 2021
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/workspace/apply.go 94.6% 100.0% 5.4

@bobcatfish
Copy link
Collaborator

image

yaaaasssss

image

@ghost
Copy link
Author

ghost commented Feb 4, 2021

Thanks for reviewing @bobcatfish !

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/workspace/apply.go 94.6% 100.0% 5.4

workspaces:
- name: signals
steps:
- image: alpine:3.12.0
Copy link
Member

Choose a reason for hiding this comment

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

NIT: step names are missing

@afrittoli
Copy link
Member

afrittoli commented Feb 9, 2021

Thank you for this, it's a great feature to add. I skimmed through the code and it looks good (thanks for nice docs 🙏 ) - the only concern I have is the lack of a feature flag. Since this adds to a beta API, adding it without a flag means that the new API field becomes beta the moment it's released.

I'm aware that we don't have a clear policy right now, I'll try to progress on https://github.com/tektoncd/community/blob/main/teps/0033-tekton-feature-gates.md so that we may have better guidance for the future.

I agree with @bobcatfish proposal to have a single API flag for (most) API changes would make sense, and I know @vdemeester expressed positive feedback to that idea, so perhaps we should add the flag along with documentation so that people may start using it.

@sbwsg @bobcatfish @vdemeester we're almost at release time, I see three alternatives:

  1. complete the work on the TEP, implement the changes associated and then merge this PR, hopefully in the next release
  2. implement an API feature flag now, rebase this one on top and they might both be merged in time for this release
  3. decide we're confident enough with this change that we want to go straight to beta

In terms of the change in behaviour (volumes being available to steps right away), I think that should be fine, I cannot imaging that change breaking anyones workflow today - is that correct?

@afrittoli
Copy link
Member

/hold until the need for a feature flag is discussed / clarified

@vdemeester
Copy link
Member

/hold

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1beta1/task_validation.go 95.8% 96.3% 0.5
pkg/workspace/apply.go 94.6% 100.0% 5.4

@ghost
Copy link
Author

ghost commented Apr 30, 2021

now that the feature gates PR is merged, this will need a rebase 🙏

Rebased on top of new feature gates code. I think this is ready for another look.

@ghost
Copy link
Author

ghost commented May 4, 2021

I'm going to cancel the hold. I can't find the comment where it was added and everythoing's up to date now with the feature gate work.

/hold cancel

@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 May 4, 2021
@@ -19,6 +19,10 @@ spec:
- name: signals
steps:
- image: alpine:3.12.0
resources:
Copy link
Member

Choose a reason for hiding this comment

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

@sbwsg I am wondering why these changes are showing up here 🤔 These were already a part of previous PR you created.

Copy link
Member

Choose a reason for hiding this comment

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

and which was merged ...

@@ -118,7 +118,7 @@ func NewFeatureFlagsFromMap(cfgMap map[string]string) (*FeatureFlags, error) {
}

// setEnabledAPIFields sets the "enable-api-fields" flag based on the content of a given map.
// If the feature gate is invalid or missing then an error is returned.
// If the feature gate is invalid or missing then the flag is set to its default.
Copy link
Member

Choose a reason for hiding this comment

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

NIT: this is not true, it does return error if the value is anything outside of stable and alpha, some git weirdness?

Copy link
Author

Choose a reason for hiding this comment

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

Ah 😅 result of a bad merge. Good catch, thank you!

@@ -135,6 +158,9 @@ spec:

#### Sharing `Workspaces` with `Sidecars`
Copy link
Member

Choose a reason for hiding this comment

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

NIT: reading for the first time looks like, the two notes in the same section is contradicting each other. The first note is saying with alpha API, the workspaces are automatically available to sidecars and second note is about stable API. With stable API, sidecars have to opt-in. This is fine for now, no need to change anything here. But we might have to repeat ourselves and be explicit about the behavior with stable compared to alpha 😞 May be keep the stable API behavior as is and add changes being introduced with alpha in the end of the section 🤔

Copy link
Author

Choose a reason for hiding this comment

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

Yeah you're right it was confusing in this context. I removed mention of the alpha api from here.

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1beta1/task_validation.go 95.8% 96.3% 0.5
pkg/workspace/apply.go 94.6% 100.0% 5.4

Copy link
Author

@ghost ghost left a comment

Choose a reason for hiding this comment

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

I rebased off of latest main; the weird artifacts are gone now.

@@ -118,7 +118,7 @@ func NewFeatureFlagsFromMap(cfgMap map[string]string) (*FeatureFlags, error) {
}

// setEnabledAPIFields sets the "enable-api-fields" flag based on the content of a given map.
// If the feature gate is invalid or missing then an error is returned.
// If the feature gate is invalid or missing then the flag is set to its default.
Copy link
Author

Choose a reason for hiding this comment

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

Ah 😅 result of a bad merge. Good catch, thank you!

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1beta1/task_validation.go 95.8% 96.3% 0.5
pkg/workspace/apply.go 94.6% 100.0% 5.4

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1beta1/task_validation.go 95.8% 96.3% 0.5
pkg/workspace/apply.go 94.6% 100.0% 5.4

for stepIdx, step := range steps {
if len(step.Workspaces) != 0 {
errs = errs.Also(ValidateEnabledAPIFields(ctx, "step workspaces", config.AlphaAPIFields).ViaIndex(stepIdx).ViaField("steps"))
}
Copy link
Member

Choose a reason for hiding this comment

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

Should we return an error here or continue validating workspaces even when a feature gate is not set to alpha? 🤔 Generally we accumulate all the validation errors before exiting.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, I've decided to leave them accumulating. We can always return early in future if we see reports that it's confusing this way.

@pritidesai
Copy link
Member

Is this feature supported for a task within a pipeline? if so, will be great to have an example for the same 🙏

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1beta1/task_validation.go 95.8% 96.3% 0.5
pkg/workspace/apply.go 94.6% 100.0% 5.4

@ghost
Copy link
Author

ghost commented May 5, 2021

Is this feature supported for a task within a pipeline? if so, will be great to have an example for the same 🙏

Added a pipelinerun example.

@pritidesai
Copy link
Member

Added a pipelinerun example.

Thanks a bunch @sbwsg, one more question (sorry for nagging on this, trying to make sure I understand it since this is the first alpha feature 😜 ). I am not seeing the examples under v1beta1/taskruns/alpha and v1beta1/pipelineruns/alpha ran as part of the integration tests. Is that expected? The examples are more of a reference rather than validating the functionality?

@afrittoli
Copy link
Member

Release Notes

- Sidecars in a Task now receive Workspaces, just like Steps do.
- Steps and Sidecars can now specify which Workspaces they want access to. This isolates the workspace to only those Steps or Sidecars that need them, allowing Task authors to limit exposure of sensitive data like credentials.
- The default behaviour for workspaces in Steps remains the same - all Steps get access to them.

Could you mention in the release notes that this change in behaviour is alpha / gated by a feature flag - so there will be no change in default behaviour when upgrading to v0.24? 🙏

@ghost
Copy link
Author

ghost commented May 5, 2021

Added a pipelinerun example.

Thanks a bunch @sbwsg, one more question (sorry for nagging on this, trying to make sure I understand it since this is the first alpha feature 😜 ). I am not seeing the examples under v1beta1/taskruns/alpha and v1beta1/pipelineruns/alpha ran as part of the integration tests. Is that expected? The examples are more of a reference rather than validating the functionality?

I created #3896 to tackle it and will pick it up asap.

Could you mention in the release notes that this change in behaviour is alpha / gated by a feature flag - so there will be no change in default behaviour when upgrading to v0.24? 🙏

Sure thing! Done.

@@ -98,6 +100,23 @@ func Apply(ts v1beta1.TaskSpec, wb []v1beta1.WorkspaceBinding, v map[string]core
ts.StepTemplate = &corev1.Container{}
}

isolatedWorkspaces := sets.NewString()

alphaAPIEnabled := config.FromContextOrDefaults(ctx).FeatureFlags.EnableAPIFields == "alpha"
Copy link
Member

Choose a reason for hiding this comment

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

NIT: can use config.AlphaAPIFields instead of string literal "alpha"

Copy link
Member

@afrittoli afrittoli left a comment

Choose a reason for hiding this comment

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

Review in progress 🙏 I will finish tomorrow if no-one gets to it first

examples/v1beta1/taskruns/alpha/workspace-isolation.yaml Outdated Show resolved Hide resolved
Access to Workspaces can now be limited to specific Steps and Sidecars in a Task.
This allows Task authors to isolate sensitive data to specific images, reducing
exposure of assets like credentials.

As a side-effect of this change Workspaces are now mounted to Sidecars by
default, just as they are to Steps.
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1beta1/task_validation.go 95.8% 96.3% 0.5
pkg/workspace/apply.go 94.6% 100.0% 5.4

if isolatedWorkspaces.Has(w.Name) {
mountAsIsolatedWorkspace(ts, w.Name, volumeMount)
} else {
mountAsSharedWorkspace(ts, volumeMount)
Copy link
Member

Choose a reason for hiding this comment

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

I am guessing this will go away once this feature is promoted to stable 🤔

Copy link
Member

Choose a reason for hiding this comment

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

or rather the else ⬇️

@@ -522,3 +524,310 @@ func TestApply(t *testing.T) {
})
}
}

func TestApply_IsolatedWorkspaces(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

NIT: The tests included here are pretty comprehensive (go coverage is very obvious) 😍 but will be great to have a test with two different workspaces out of which one is isolated to a step and one is isolated to a sidecar.

@pritidesai
Copy link
Member

thanks a bunch @sbwsg for your patience on this 🙏

It looks great. I am a little nervous without having alpha examples running as part of the CI process. But not a blocker here. I have validated all the examples on my local cluster and works smooth. We can wait until #3896 is implemented (hopefully soon 🤞). I have also validated workspaces.yaml pipelineRun with alpha API and works as expected without any issues.

/lgtm

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. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve UX of getting credentials into Tasks
6 participants