-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lockdown /tekton/step folders to their own steps.
This change symlinks /tekton/step folders to a step's corresponding /tekton/run folder. This is an incremental change to lock down the /tekton folder to prevent tampering of exitCode files from other steps. Note: this does not completely protect against a step from tampering from its own output - more work will needed in a future PR to fully lock this down, but this is a step in the right direction (and a complete fix will likely require a more involved design). While /tekton/steps is now considered an implementation detail and could potentially be removed, the folder is preserved for now to limit the scope of this PR. - Moves `exitCode` output to `/tekton/run/<step #>/status` - Symlinks `/tekton/steps/<step #>` and `/tekton/steps/<step name>` to `/tekton/run/<step #>/status`. - Creates new `tekton-init` entrypoint subcommand to initialize the Tekton step directory. - Removes `-step_metadata_dir_link` flag from the main entrypoint binary (this behavior is now handled by the initcontainer). Co-authored-by: Lee Bernick <leebernick@google.com>
- Loading branch information
Showing
16 changed files
with
382 additions
and
350 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package subcommands | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"strconv" | ||
) | ||
|
||
// StepInitCommand is the name of the /tekton/steps initialization command. | ||
const StepInitCommand = "step-init" | ||
|
||
var ( | ||
// root is the location of the Tekton root directory. | ||
// Included as a global variable to allow overriding for tests. | ||
tektonRoot = "/tekton" | ||
) | ||
|
||
// stepInit sets up the /tekton/steps directory for the pod. | ||
// This expects the list of steps (in order matching the Task spec). | ||
func stepInit(steps []string) error { | ||
// Setup step directory symlinks - step data is written to a /tekton/run/<step>/status | ||
// folder corresponding to each step - this is only mounted RW for the matching user step | ||
// (and RO for all other steps). | ||
// /tekton/steps provides a convenience symlink so that Tekton utilities to reference steps | ||
// by name or index. | ||
// NOTE: /tekton/steps may be removed in the future. Prefer using /tekton/run directly if | ||
// possible. | ||
|
||
// Create directory if it doesn't already exist | ||
stepDir := filepath.Join(tektonRoot, "steps") | ||
if err := os.MkdirAll(stepDir, os.ModePerm); err != nil { | ||
log.Fatalf("Error creating steps directory %q: %v", stepDir, err) | ||
} | ||
|
||
for i, s := range steps { | ||
run := filepath.Join(tektonRoot, "run", strconv.Itoa(i), "status") | ||
if err := os.Symlink(run, filepath.Join(stepDir, s)); err != nil { | ||
return err | ||
} | ||
if err := os.Symlink(run, filepath.Join(stepDir, strconv.Itoa(i))); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package subcommands | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
func TestStepInit(t *testing.T) { | ||
tmp, err := ioutil.TempDir("", "step-init-*") | ||
if err != nil { | ||
t.Fatalf("error creating temp directory: %v", err) | ||
} | ||
defer os.RemoveAll(tmp) | ||
|
||
// Override tektonRoot for testing. | ||
tektonRoot = tmp | ||
|
||
// Create step directory so that symlinks can be successfully created. | ||
// This is typically done by volume mounts, so it needs to be done manually | ||
// in tests. | ||
stepDir := filepath.Join(tmp, "steps") | ||
if err := os.Mkdir(stepDir, os.ModePerm); err != nil { | ||
t.Fatalf("error creating step directory: %v", err) | ||
} | ||
|
||
steps := []string{"a", "b"} | ||
if err := stepInit(steps); err != nil { | ||
t.Fatalf("stepInit: %v", err) | ||
} | ||
|
||
// Map of symlinks to expected /tekton/run folders. | ||
// Expected format: | ||
// Key: /tekton/steps/<key> | ||
// Value: /tekton/run/<value>/status | ||
wantLinks := map[string]string{ | ||
"a": "0", | ||
"0": "0", | ||
"b": "1", | ||
"1": "1", | ||
} | ||
|
||
direntry, err := os.ReadDir(stepDir) | ||
if err != nil { | ||
t.Fatalf("os.ReadDir: %v", err) | ||
} | ||
for _, de := range direntry { | ||
t.Run(de.Name(), func(t *testing.T) { | ||
l, err := os.Readlink(filepath.Join(stepDir, de.Name())) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
want, ok := wantLinks[de.Name()] | ||
if !ok { | ||
t.Fatalf("unexpected symlink: %s", de.Name()) | ||
} | ||
if wantDir := filepath.Join(tmp, "run", want, "status"); l != wantDir { | ||
t.Errorf("want %s, got %s", wantDir, l) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.