mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-09-19 12:34:44 -04:00
api: add functions to transparently handle signatures upon API interaction (#2142)
This commit is contained in:
parent
002c3a9a32
commit
dac690656e
45 changed files with 707 additions and 472 deletions
|
@ -67,7 +67,7 @@ func (a *Archivist) Close(ctx context.Context) error {
|
|||
|
||||
// Archive reads the OS image in img and uploads it as key.
|
||||
func (a *Archivist) Archive(ctx context.Context, version versionsapi.Version, csp, attestationVariant string, img io.Reader) (string, error) {
|
||||
key, err := url.JoinPath(version.ArtifactPath(versionsapi.APIV1), version.Kind.String(), "csp", csp, attestationVariant, "image.raw")
|
||||
key, err := url.JoinPath(version.ArtifactPath(versionsapi.APIV1), version.Kind().String(), "csp", csp, attestationVariant, "image.raw")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ func New(region, bucketName string, log *logger.Logger) (*Uploader, error) {
|
|||
|
||||
// Upload uploads an OS image to AWS.
|
||||
func (u *Uploader) Upload(ctx context.Context, req *osimage.UploadRequest) ([]versionsapi.ImageInfoEntry, error) {
|
||||
blobName := fmt.Sprintf("image-%s-%s-%d.raw", req.Version.Stream, req.Version.Version, req.Timestamp.Unix())
|
||||
blobName := fmt.Sprintf("image-%s-%s-%d.raw", req.Version.Stream(), req.Version.Version(), req.Timestamp.Unix())
|
||||
imageName := imageName(req.Version, req.AttestationVariant, req.Timestamp)
|
||||
allRegions := []string{u.region}
|
||||
allRegions = append(allRegions, replicationRegions...)
|
||||
|
@ -479,10 +479,10 @@ func (u *Uploader) ensureImageDeleted(ctx context.Context, imageName, region str
|
|||
}
|
||||
|
||||
func imageName(version versionsapi.Version, attestationVariant string, timestamp time.Time) string {
|
||||
if version.Stream == "stable" {
|
||||
return fmt.Sprintf("constellation-%s-%s", version.Version, attestationVariant)
|
||||
if version.Stream() == "stable" {
|
||||
return fmt.Sprintf("constellation-%s-%s", version.Version(), attestationVariant)
|
||||
}
|
||||
return fmt.Sprintf("constellation-%s-%s-%s-%s", version.Stream, version.Version, attestationVariant, timestamp.Format(timestampFormat))
|
||||
return fmt.Sprintf("constellation-%s-%s-%s-%s", version.Stream(), version.Version(), attestationVariant, timestamp.Format(timestampFormat))
|
||||
}
|
||||
|
||||
func waitForSnapshotImport(ctx context.Context, ec2C ec2API, importTaskID string) (string, error) {
|
||||
|
|
|
@ -95,9 +95,9 @@ func New(subscription, location, resourceGroup string, log *logger.Logger) (*Upl
|
|||
// Upload uploads an OS image to Azure.
|
||||
func (u *Uploader) Upload(ctx context.Context, req *osimage.UploadRequest) ([]versionsapi.ImageInfoEntry, error) {
|
||||
formattedTime := req.Timestamp.Format(timestampFormat)
|
||||
diskName := fmt.Sprintf("constellation-%s-%s-%s", req.Version.Stream, formattedTime, req.AttestationVariant)
|
||||
diskName := fmt.Sprintf("constellation-%s-%s-%s", req.Version.Stream(), formattedTime, req.AttestationVariant)
|
||||
var sigName string
|
||||
switch req.Version.Stream {
|
||||
switch req.Version.Stream() {
|
||||
case "stable":
|
||||
sigName = sigNameStable
|
||||
case "debug":
|
||||
|
@ -517,12 +517,12 @@ func uploadChunk(ctx context.Context, uploader azurePageblobAPI, chunk io.ReadSe
|
|||
|
||||
func imageOffer(version versionsapi.Version) string {
|
||||
switch {
|
||||
case version.Stream == "stable":
|
||||
case version.Stream() == "stable":
|
||||
return "constellation"
|
||||
case version.Stream == "debug" && version.Ref == "-":
|
||||
return version.Version
|
||||
case version.Stream() == "debug" && version.Ref() == "-":
|
||||
return version.Version()
|
||||
}
|
||||
return version.Ref + "-" + version.Stream
|
||||
return version.Ref() + "-" + version.Stream()
|
||||
}
|
||||
|
||||
// imageVersion determines the semantic version string used inside a sig image.
|
||||
|
@ -530,10 +530,10 @@ func imageOffer(version versionsapi.Version) string {
|
|||
// Otherwise, the version is derived from the commit timestamp.
|
||||
func imageVersion(version versionsapi.Version, timestamp time.Time) (string, error) {
|
||||
switch {
|
||||
case version.Stream == "stable":
|
||||
case version.Stream() == "stable":
|
||||
fallthrough
|
||||
case version.Stream == "debug" && version.Ref == "-":
|
||||
return strings.TrimLeft(version.Version, "v"), nil
|
||||
case version.Stream() == "debug" && version.Ref() == "-":
|
||||
return strings.TrimLeft(version.Version(), "v"), nil
|
||||
}
|
||||
|
||||
formattedTime := timestamp.Format(timestampFormat)
|
||||
|
|
|
@ -225,16 +225,16 @@ func (u *Uploader) blobURL(blobName string) string {
|
|||
}
|
||||
|
||||
func (u *Uploader) imageName(version versionsapi.Version, attestationVariant string) string {
|
||||
return strings.ReplaceAll(version.Version, ".", "-") + "-" + attestationVariant + "-" + version.Stream
|
||||
return strings.ReplaceAll(version.Version(), ".", "-") + "-" + attestationVariant + "-" + version.Stream()
|
||||
}
|
||||
|
||||
func (u *Uploader) imageFamily(version versionsapi.Version) string {
|
||||
if version.Stream == "stable" {
|
||||
if version.Stream() == "stable" {
|
||||
return "constellation"
|
||||
}
|
||||
truncatedRef := version.Ref
|
||||
if len(version.Ref) > 45 {
|
||||
truncatedRef = version.Ref[:45]
|
||||
truncatedRef := version.Ref()
|
||||
if len(version.Ref()) > 45 {
|
||||
truncatedRef = version.Ref()[:45]
|
||||
}
|
||||
return "constellation-" + truncatedRef
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
s3manager "github.com/aws/aws-sdk-go-v2/feature/s3/manager"
|
||||
|
@ -67,13 +68,11 @@ func (a *Uploader) Close(ctx context.Context) error {
|
|||
|
||||
// Upload marshals the image info to JSON and uploads it to S3.
|
||||
func (a *Uploader) Upload(ctx context.Context, imageInfo versionsapi.ImageInfo) (string, error) {
|
||||
ver := versionsapi.Version{
|
||||
Ref: imageInfo.Ref,
|
||||
Stream: imageInfo.Stream,
|
||||
Version: imageInfo.Version,
|
||||
Kind: versionsapi.VersionKindImage,
|
||||
ver, err := versionsapi.NewVersion(imageInfo.Ref, imageInfo.Stream, imageInfo.Version, versionsapi.VersionKindImage)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("creating version: %w", err)
|
||||
}
|
||||
key, err := url.JoinPath(ver.ArtifactPath(versionsapi.APIV2), ver.Kind.String(), "info.json")
|
||||
key, err := url.JoinPath(ver.ArtifactPath(versionsapi.APIV2), ver.Kind().String(), "info.json")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
@ -78,17 +78,15 @@ func (a *Uploader) Upload(ctx context.Context, rawMeasurement, signature io.Read
|
|||
return "", "", err
|
||||
}
|
||||
|
||||
ver := versionsapi.Version{
|
||||
Ref: measurements.Ref,
|
||||
Stream: measurements.Stream,
|
||||
Version: measurements.Version,
|
||||
Kind: versionsapi.VersionKindImage,
|
||||
ver, err := versionsapi.NewVersion(measurements.Ref, measurements.Stream, measurements.Version, versionsapi.VersionKindImage)
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("creating version: %w", err)
|
||||
}
|
||||
key, err := url.JoinPath(ver.ArtifactPath(versionsapi.APIV2), ver.Kind.String(), "measurements.json")
|
||||
key, err := url.JoinPath(ver.ArtifactPath(versionsapi.APIV2), ver.Kind().String(), "measurements.json")
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
sigKey, err := url.JoinPath(ver.ArtifactPath(versionsapi.APIV2), ver.Kind.String(), "measurements.json.sig")
|
||||
sigKey, err := url.JoinPath(ver.ArtifactPath(versionsapi.APIV2), ver.Kind().String(), "measurements.json.sig")
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue