Skip to content

Commit 9e44cef

Browse files
authored
Merge pull request #2713 from stgraber/main
2 parents 8822c0a + 6143063 commit 9e44cef

File tree

9 files changed

+49
-7
lines changed

9 files changed

+49
-7
lines changed

client/oci_images.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package incus
33
import (
44
"compress/gzip"
55
"context"
6+
"crypto/sha256"
67
"encoding/base64"
78
"encoding/json"
89
"errors"
@@ -30,6 +31,7 @@ type ociInfo struct {
3031
Digest string `json:"Digest"`
3132
Created time.Time `json:"Created"`
3233
Architecture string `json:"Architecture"`
34+
Layers []string `json:"Layers"`
3335
LayersData []struct {
3436
Size int64 `json:"Size"`
3537
} `json:"LayersData"`
@@ -417,7 +419,7 @@ func (r *ProtocolOCI) GetImageAlias(name string) (*api.ImageAliasesEntry, string
417419
}
418420

419421
info.Alias = name
420-
info.Digest = strings.Replace(info.Digest, "sha256:", "", 1)
422+
info.Digest = r.computeFingerprint(info.Layers)
421423

422424
archID, err := osarch.ArchitectureID(info.Architecture)
423425
if err != nil {
@@ -478,3 +480,13 @@ func (r *ProtocolOCI) GetImageAliasArchitectures(imageType string, name string)
478480
func (r *ProtocolOCI) ExportImage(_ string, _ api.ImageExportPost) (Operation, error) {
479481
return nil, errors.New("Exporting images is not supported with OCI registry")
480482
}
483+
484+
func (r *ProtocolOCI) computeFingerprint(layers []string) string {
485+
h := sha256.New()
486+
487+
for _, layer := range layers {
488+
h.Write([]byte(layer))
489+
}
490+
491+
return fmt.Sprintf("%x", h.Sum(nil))
492+
}

cmd/incusd/instance_console.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,11 +719,16 @@ func instanceConsoleLogGet(d *Daemon, r *http.Request) response.Response {
719719

720720
var headers map[string]string
721721
if consoleLogType == "vga" {
722-
screenshotFile, err := os.CreateTemp(v.Path(), "screenshot-*.png")
722+
screenshotFile, err := os.Create(fmt.Sprintf("/tmp/incus_screenshot_%d", inst.ID()))
723723
if err != nil {
724724
return response.SmartError(fmt.Errorf("Couldn't create screenshot file: %w", err))
725725
}
726726

727+
err = screenshotFile.Chmod(0o600)
728+
if err != nil {
729+
return response.SmartError(err)
730+
}
731+
727732
ent.Cleanup = func() {
728733
_ = screenshotFile.Close()
729734
_ = os.Remove(screenshotFile.Name())

internal/server/apparmor/instance.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
type instance interface {
2626
Project() api.Project
2727
Name() string
28+
ID() int
2829
ExpandedConfig() map[string]string
2930
Type() instancetype.Type
3031
LogPath() string
@@ -271,6 +272,7 @@ func instanceProfile(sysOS *sys.OS, inst instance, extraBinaries []string) (stri
271272
"libraryPath": strings.Split(os.Getenv("LD_LIBRARY_PATH"), ":"),
272273
"logPath": inst.LogPath(),
273274
"runPath": inst.RunPath(),
275+
"id": inst.ID(),
274276
"name": InstanceProfileName(inst),
275277
"path": path,
276278
"raw": rawContent,

internal/server/apparmor/instance_qemu.profile.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ profile "{{ .name }}" flags=(attach_disconnected,mediate_deleted) {
7272
{{ .runPath }}/** rwk,
7373
{{ .path }}/** rwk,
7474
{{ .devicesPath }}/** rwk,
75+
/tmp/incus_screenshot_{{ .id }} rwk,
7576
7677
# Needed for the fork sub-commands
7778
{{ .exePath }} mr,

internal/server/device/pci/pci.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,14 @@ func DeviceDriverOverride(pciDev Device, driverOverride string) error {
108108
reverter := revert.New()
109109
defer reverter.Fail()
110110

111+
// Check if already bound to the target driver.
112+
_, err := os.Stat(filepath.Join("/sys/bus/pci/drivers", driverOverride, pciDev.SlotName))
113+
if err == nil {
114+
return nil
115+
}
116+
111117
// Unbind the device from the host (ignore if not bound).
112-
err := DeviceUnbind(pciDev)
118+
err = DeviceUnbind(pciDev)
113119
if err != nil && errors.Is(err, fs.ErrNotExist) {
114120
return err
115121
}

internal/server/network/acl/driver_common.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -682,9 +682,13 @@ func (d *common) Update(config *api.NetworkACLPut, clientType request.ClientType
682682
return err
683683
}
684684

685-
err = FirewallApplyACLRules(d.state, d.logger, d.projectName, aclNet)
686-
if err != nil {
687-
return err
685+
// Only trigger application on related bridged networks that directly use the ACL.
686+
networkACLs := util.SplitNTrimSpace(aclNet.Config["security.acls"], ",", -1, true)
687+
if slices.Contains(networkACLs, d.info.Name) {
688+
err = FirewallApplyACLRules(d.state, d.logger, d.projectName, aclNet)
689+
if err != nil {
690+
return err
691+
}
688692
}
689693
}
690694

internal/server/operations/util.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ func SetProgressMetadata(metadata map[string]any, stage, displayPrefix string, p
5858
}
5959
} else if processed > 0 {
6060
metadata[stage+"_progress"] = fmt.Sprintf("%s: %s (%s/s)", displayPrefix, units.GetByteSizeString(processed, 2), units.GetByteSizeString(speed, 2))
61-
} else {
61+
} else if speed > 0 {
6262
metadata[stage+"_progress"] = fmt.Sprintf("%s: %s/s", displayPrefix, units.GetByteSizeString(speed, 2))
63+
} else {
64+
metadata[stage+"_progress"] = displayPrefix
6365
}
6466
}

shared/archive/archive.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ func Unpack(file string, path string, blockBackend bool, maxMemory int64, tracke
187187
allowedCmds = append(allowedCmds, unpacker[0])
188188
}
189189
} else if strings.HasPrefix(extension, ".squashfs") {
190+
// Progress tracking with squashfs doesn't work as it needs to seek the file.
191+
if tracker.Handler != nil {
192+
tracker.Handler(0, 0)
193+
}
194+
190195
// unsquashfs does not support reading from stdin,
191196
// so ProgressTracker is not possible.
192197
command = "unsquashfs"

shared/ioprogress/tracker.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ func (pt *ProgressTracker) update(n int) {
6262
if pt.Length > 0 {
6363
pt.percentage = percentage
6464
progressInt = min(int64(1+int(percentage)), 100)
65+
66+
// Cap maximum download speed to file size.
67+
if speedInt > pt.Length {
68+
speedInt = pt.Length
69+
}
6570
} else {
6671
progressInt = pt.total
6772

0 commit comments

Comments
 (0)