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

Cache support #17

Merged
merged 15 commits into from
Aug 3, 2020
Merged

Cache support #17

merged 15 commits into from
Aug 3, 2020

Conversation

edigaryev
Copy link
Contributor

This implementation attempts to support parallel CLI executions and has no automatic cleaning for now.

This implementation attempts to support parallel CLI executions
and has no automatic cleaning for now.
This ensures that we will also create OS-dependent cache directory
if it doesn't exist yet.
Pass everything to Cirrus CI annotations.
)

type PutOperation struct {
tmpBlobFile *os.File
Copy link
Contributor

Choose a reason for hiding this comment

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

let's use a buffered writer here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See 424a4fa.

}

func (c *Cache) blobPath(key string) string {
// Sanitize user-controlled data by hashing it
Copy link
Contributor

Choose a reason for hiding this comment

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

Might not be necessary since cache keys are always in this form <cache name>-<sha256>. Plus will be easier for users to find the blobs for manual inspection.

Copy link
Contributor Author

@edigaryev edigaryev Aug 3, 2020

Choose a reason for hiding this comment

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

It's technically possible for the arbitrary code that runs in the task's environment to impersonate the agent and connect to the CLI over new (or existing) RPC connection.

So this depends on whether we trust that environment or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alternatively, we can validate the key using a simple regular expression.

Copy link
Contributor

@fkorotkov fkorotkov Aug 3, 2020

Choose a reason for hiding this comment

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

Yeah, can do something like:

Suggested change
// Sanitize user-controlled data by hashing it
isSafeChar := func(c rune) bool {
if '0' <= c && c <= '9' { return true }
if 'a' <= c && c <= 'z' { return true }
if 'A' <= c && c <= 'Z' { return true }
if c == '-' || c == '_' { return true }
return false
}
isNotSafeChar := func(c rune) bool {
return !isSafeChar(c)
}
containsNonSafeChar := strings.IndexFunc(key, isNotSafeChar) >= 0
if !containsNonSafeChar {
// only safe characters so no need for a sanitization
return key
}
// Sanitize user-controlled data by hashing it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See 379f4a2.

Copy link
Contributor

@fkorotkov fkorotkov left a comment

Choose a reason for hiding this comment

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

Looks great! Left a few nitpicks.

2020/08/03 13:14:37 Failed to download test-e7c76decfad1e83298b9a9ddf7f2f37ad42da790a1d665b6a2404c3c82b66e48 cache! rpc error: code = ResourceExhausted desc = grpc: received message larger than max (10485765 vs. 4194304)
@edigaryev edigaryev merged commit 6a96f43 into master Aug 3, 2020
@fkorotkov fkorotkov deleted the cache branch August 3, 2020 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants