-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Proof-of-concept draft for teleport-update binary implementation #46357
Conversation
endpoint := fmt.Sprintf("https://%s/webapi/find", cfg.ProxyAddr) | ||
|
||
if cfg.Group != "" { | ||
endpoint = fmt.Sprintf("%s?group=%s", endpoint, cfg.Group) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The group content is not urlencoded and the query building is fragile. The url
lib allows to do this safely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, totally agree, was just using this to test
func (tv *TeleportVersion) Remove(version string) error { | ||
versionPath := filepath.Join(tv.VersionsDir, version) | ||
sumPath := filepath.Join(versionPath, checksumType) | ||
|
||
// invalidate checksum first, to protect against partially-removed | ||
// directory with valid checksum. | ||
if err := os.Remove(sumPath); err != nil { | ||
return trace.Wrap(err) | ||
} | ||
if err := os.RemoveAll(versionPath); err != nil { | ||
return trace.Wrap(err) | ||
} | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function should not allow to delete the current active version.
sum, err := hex.DecodeString(raw) | ||
if err != nil { | ||
plog.WarnContext(ctx, "corrupt checksum detected", "size", n, "checksum", raw) | ||
return nil, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning nil while we failed to read the checksum is not consistent with the other error return paths of the function: e.g. we can't open the file. If the goal is to continue the execution, it would be clearer to return an error and handle it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, will add a typed error in the separate PR for this function.
} | ||
raw := buf.String() | ||
if n != 64 { | ||
plog.WarnContext(ctx, "unexpected checksum size", "size", n, "checksum", raw) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An unexpected size should cause an immediate failure, there is no need to try to decode a buffer that has the wrong length.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will cover this with a typed error (same as below)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: might be replaced with io.CopyN
which actually does the same, and returns EOF
if n is less than expected
return nil, nil, trace.Errorf("size of download (%d bytes) exceeds available disk space (%d bytes)", resp.ContentLength, free) | ||
} | ||
|
||
// Calculate checksum concurrently with download. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the motivation behind checksuming as we download versus reading the file back from the fs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No downside to it, and it avoids needed to re-read the file from disk
Co-authored-by: Hugo Shaka <[email protected]>
Co-authored-by: Hugo Shaka <[email protected]>
Co-authored-by: Hugo Shaka <[email protected]>
Completed by #47565 |
This PR contains an initial draft of the
teleport-update
binary described in #40190.Not all functionality is implemented, only:
/var/lib/teleport/versions/X.Y.Z
, with disk space checks, checksum verification, and protection against power loss scenarios.updates.yaml
This PR will not be merged as-is, and is only open for early review of the approach.
I plan to break this download into separate, tested PRs if this initial version looks good.