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

Windows "filesystemStore" issue with consistent snapshots #273

Closed
torin-carey opened this issue Apr 20, 2022 · 0 comments · Fixed by #274
Closed

Windows "filesystemStore" issue with consistent snapshots #273

torin-carey opened this issue Apr 20, 2022 · 0 comments · Fixed by #274
Assignees
Labels

Comments

@torin-carey
Copy link
Contributor

When dealing with the filesystemStore local store implementation, there are issues using the consistent snapshot option where targets will not have filenames with prepended hashes, preventing clients finding targets in the repo.

Following a simple repo creation with cmd/tuf and consistent snapshots:

> .\tuf.exe init
Repository initialized
> .\tuf.exe gen-key root
...
> .\tuf.exe gen-key targets
...
> .\tuf.exe gen-key snapshot
...
> .\tuf.exe gen-key timestamp
...
> .\tuf.exe sign root.json
Signed root.json with 1 key(s)
> New-Item .\staged\targets\file -type file
> .\tuf.exe add .\file
Added/staged targets:
* file
> .\tuf.exe sign targets.json
Signed targets.json with 1 key(s)
> .\tuf.exe snapshot
Staged snapshot.json metadata with expiration date: ...
> .\tuf.exe sign snapshot.json
Signed snapshot.json with 1 key(s)
> .\tuf.exe timstamp
Staged timestamp.json metadata with expiration date: ...
> .\tuf.exe sign timestamp.json
Signed timestamp.json with 1 key(s)
> .\tuf.exe commit
Committed successfully

Following this, our file target ends up in repository\targets\file, which is incorrect since we have consistent snapshots enabled.
We would expect, and following the same process on Linux we would see, that the file should end up prepended with a hash, such as
repository\targets\cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e.file.

The problem is that the filesystemStore local store implementation conflates filepaths and paths, which of course are different on Windows. Because of this it sees targets\file as a metadata file rather than a target:

// local_store.go
func (f *fileSystemStore) Commit(consistentSnapshot bool, versions map[string]int, hashes map[string]data.Hashes) error {
	isTarget := func(path string) bool {
		return strings.HasPrefix(path, "targets/")
	}
	copyToRepo := func(path string, info os.FileInfo, err error) error {
		if err != nil {
			return err
		}
		if info.IsDir() || !info.Mode().IsRegular() {
			return nil
		}
		rel, err := filepath.Rel(f.stagedDir(), path)
		if err != nil {
			return err
		}

		var paths []string
		if isTarget(rel) {
			paths = computeTargetPaths(consistentSnapshot, rel, hashes)
		} else {
			paths = computeMetadataPaths(consistentSnapshot, rel, versions)
		}
		// ...
	}
	// ...
	if err := filepath.Walk(f.stagedDir(), copyToRepo); err != nil {
		return err
	}
	// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants