feat(storepkg): install packages from a signed default catalogue, listed on the Extensions page
This commit is contained in:
1 parent
8d73280633
commit
28bb4b4483
15 files changed
+1334
-570
No files matched your search
@@ -271,8 +271,9 @@ func (b *server) stateStoreDeps(grants *staterpc.TaskGrants) staterpc.Deps {
|
||||
}
|
||||
if b.pg != nil {
|
||||
packages := storepkg.Service{
|
||||
Registry: registry.OCIRegistry{},
|
||||
Store: postgres.NewInstalledPackages(b.pg),
|
||||
Registry: registry.OCIRegistry{},
|
||||
Store: postgres.NewInstalledPackages(b.pg),
|
||||
Catalogue: registry.DefaultCatalogue(),
|
||||
}
|
||||
// A projection failure degrades the org resources a package would have
|
||||
// contributed to, the way a group above degrades: the State Store boots
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -20,6 +20,8 @@ const _ = grpc.SupportPackageIsVersion9
|
||||
|
||||
const (
|
||||
StateStoreService_InstallPackage_FullMethodName = "/state.v1.StateStoreService/InstallPackage"
|
||||
StateStoreService_ListCatalogue_FullMethodName = "/state.v1.StateStoreService/ListCatalogue"
|
||||
StateStoreService_InstallFromCatalogue_FullMethodName = "/state.v1.StateStoreService/InstallFromCatalogue"
|
||||
StateStoreService_GetInstalledPackage_FullMethodName = "/state.v1.StateStoreService/GetInstalledPackage"
|
||||
StateStoreService_ListInstalledPackages_FullMethodName = "/state.v1.StateStoreService/ListInstalledPackages"
|
||||
StateStoreService_AcceptPackageAuthority_FullMethodName = "/state.v1.StateStoreService/AcceptPackageAuthority"
|
||||
@@ -156,6 +158,10 @@ const (
|
||||
type StateStoreServiceClient interface {
|
||||
// Installed Archie packages. Administrative until org-scoped principals land.
|
||||
InstallPackage(ctx context.Context, in *InstallPackageRequest, opts ...grpc.CallOption) (*InstallPackageResponse, error)
|
||||
// ListCatalogue returns the packages the instance's verified catalogue
|
||||
// offers; InstallFromCatalogue installs one by name at the digest it lists.
|
||||
ListCatalogue(ctx context.Context, in *ListCatalogueRequest, opts ...grpc.CallOption) (*ListCatalogueResponse, error)
|
||||
InstallFromCatalogue(ctx context.Context, in *InstallFromCatalogueRequest, opts ...grpc.CallOption) (*InstallFromCatalogueResponse, error)
|
||||
GetInstalledPackage(ctx context.Context, in *GetInstalledPackageRequest, opts ...grpc.CallOption) (*GetInstalledPackageResponse, error)
|
||||
ListInstalledPackages(ctx context.Context, in *ListInstalledPackagesRequest, opts ...grpc.CallOption) (*ListInstalledPackagesResponse, error)
|
||||
// AcceptPackageAuthority records the operator's accepted authority against
|
||||
@@ -390,6 +396,26 @@ func (c *stateStoreServiceClient) InstallPackage(ctx context.Context, in *Instal
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *stateStoreServiceClient) ListCatalogue(ctx context.Context, in *ListCatalogueRequest, opts ...grpc.CallOption) (*ListCatalogueResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(ListCatalogueResponse)
|
||||
err := c.cc.Invoke(ctx, StateStoreService_ListCatalogue_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *stateStoreServiceClient) InstallFromCatalogue(ctx context.Context, in *InstallFromCatalogueRequest, opts ...grpc.CallOption) (*InstallFromCatalogueResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(InstallFromCatalogueResponse)
|
||||
err := c.cc.Invoke(ctx, StateStoreService_InstallFromCatalogue_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *stateStoreServiceClient) GetInstalledPackage(ctx context.Context, in *GetInstalledPackageRequest, opts ...grpc.CallOption) (*GetInstalledPackageResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(GetInstalledPackageResponse)
|
||||
@@ -1631,6 +1657,10 @@ func (c *stateStoreServiceClient) AssignAgent(ctx context.Context, in *AssignAge
|
||||
type StateStoreServiceServer interface {
|
||||
// Installed Archie packages. Administrative until org-scoped principals land.
|
||||
InstallPackage(context.Context, *InstallPackageRequest) (*InstallPackageResponse, error)
|
||||
// ListCatalogue returns the packages the instance's verified catalogue
|
||||
// offers; InstallFromCatalogue installs one by name at the digest it lists.
|
||||
ListCatalogue(context.Context, *ListCatalogueRequest) (*ListCatalogueResponse, error)
|
||||
InstallFromCatalogue(context.Context, *InstallFromCatalogueRequest) (*InstallFromCatalogueResponse, error)
|
||||
GetInstalledPackage(context.Context, *GetInstalledPackageRequest) (*GetInstalledPackageResponse, error)
|
||||
ListInstalledPackages(context.Context, *ListInstalledPackagesRequest) (*ListInstalledPackagesResponse, error)
|
||||
// AcceptPackageAuthority records the operator's accepted authority against
|
||||
@@ -1858,6 +1888,12 @@ type UnimplementedStateStoreServiceServer struct{}
|
||||
func (UnimplementedStateStoreServiceServer) InstallPackage(context.Context, *InstallPackageRequest) (*InstallPackageResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method InstallPackage not implemented")
|
||||
}
|
||||
func (UnimplementedStateStoreServiceServer) ListCatalogue(context.Context, *ListCatalogueRequest) (*ListCatalogueResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method ListCatalogue not implemented")
|
||||
}
|
||||
func (UnimplementedStateStoreServiceServer) InstallFromCatalogue(context.Context, *InstallFromCatalogueRequest) (*InstallFromCatalogueResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method InstallFromCatalogue not implemented")
|
||||
}
|
||||
func (UnimplementedStateStoreServiceServer) GetInstalledPackage(context.Context, *GetInstalledPackageRequest) (*GetInstalledPackageResponse, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "method GetInstalledPackage not implemented")
|
||||
}
|
||||
@@ -2257,6 +2293,42 @@ func _StateStoreService_InstallPackage_Handler(srv interface{}, ctx context.Cont
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _StateStoreService_ListCatalogue_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ListCatalogueRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(StateStoreServiceServer).ListCatalogue(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: StateStoreService_ListCatalogue_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(StateStoreServiceServer).ListCatalogue(ctx, req.(*ListCatalogueRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _StateStoreService_InstallFromCatalogue_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(InstallFromCatalogueRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(StateStoreServiceServer).InstallFromCatalogue(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: StateStoreService_InstallFromCatalogue_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(StateStoreServiceServer).InstallFromCatalogue(ctx, req.(*InstallFromCatalogueRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _StateStoreService_GetInstalledPackage_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetInstalledPackageRequest)
|
||||
if err := dec(in); err != nil {
|
||||
@@ -4407,6 +4479,14 @@ var StateStoreService_ServiceDesc = grpc.ServiceDesc{
|
||||
MethodName: "InstallPackage",
|
||||
Handler: _StateStoreService_InstallPackage_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "ListCatalogue",
|
||||
Handler: _StateStoreService_ListCatalogue_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "InstallFromCatalogue",
|
||||
Handler: _StateStoreService_InstallFromCatalogue_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetInstalledPackage",
|
||||
Handler: _StateStoreService_GetInstalledPackage_Handler,
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
package storepkg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// ErrCatalogueUnavailable means no catalogue is configured for this instance.
|
||||
var ErrCatalogueUnavailable = errors.New("no package catalogue is configured")
|
||||
|
||||
// CatalogueEntry is one package a catalogue offers: where it is and the
|
||||
// digest that pins it.
|
||||
type CatalogueEntry struct {
|
||||
Name string `json:"name"`
|
||||
Surface string `json:"surface"`
|
||||
Version string `json:"version"`
|
||||
Description string `json:"description"`
|
||||
Reference string `json:"reference"`
|
||||
Digest string `json:"digest"`
|
||||
}
|
||||
|
||||
// Catalogue is a verified list of packages.
|
||||
type Catalogue struct {
|
||||
Packages []CatalogueEntry `json:"packages"`
|
||||
}
|
||||
|
||||
// Validate refuses an entry an install could not pin.
|
||||
func (c Catalogue) Validate() error {
|
||||
seen := make(map[string]bool, len(c.Packages))
|
||||
for _, entry := range c.Packages {
|
||||
switch {
|
||||
case entry.Name == "" || entry.Reference == "":
|
||||
return fmt.Errorf("catalogue entry %q: name and reference are required", entry.Name)
|
||||
case !digestPattern.MatchString(entry.Digest):
|
||||
return fmt.Errorf("catalogue entry %q: digest must be a sha256 digest", entry.Name)
|
||||
case seen[entry.Name]:
|
||||
return fmt.Errorf("catalogue entry %q: listed twice", entry.Name)
|
||||
}
|
||||
seen[entry.Name] = true
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CatalogueSource fetches a catalogue and verifies its signature. An
|
||||
// unverifiable catalogue is an error, never an empty list.
|
||||
type CatalogueSource interface {
|
||||
Fetch(context.Context) (Catalogue, error)
|
||||
}
|
||||
|
||||
// ListCatalogue returns the verified catalogue.
|
||||
func (s Service) ListCatalogue(ctx context.Context) (Catalogue, error) {
|
||||
if s.Catalogue == nil {
|
||||
return Catalogue{}, ErrCatalogueUnavailable
|
||||
}
|
||||
return s.Catalogue.Fetch(ctx)
|
||||
}
|
||||
|
||||
// InstallFromCatalogue installs name at the reference and digest the verified
|
||||
// catalogue lists, so a package is never installed from an unverified tag.
|
||||
func (s Service) InstallFromCatalogue(ctx context.Context, orgID, name string) (Installed, error) {
|
||||
catalogue, err := s.ListCatalogue(ctx)
|
||||
if err != nil {
|
||||
return Installed{}, err
|
||||
}
|
||||
for _, entry := range catalogue.Packages {
|
||||
if entry.Name == name {
|
||||
return s.Install(ctx, orgID, entry.Name, entry.Reference, entry.Digest)
|
||||
}
|
||||
}
|
||||
return Installed{}, fmt.Errorf("catalogue package %q: %w", name, ErrNotFound)
|
||||
}
|
||||
@@ -60,6 +60,8 @@ type Manager interface {
|
||||
ListInstalled(context.Context, string) ([]Installed, error)
|
||||
RemoveInstalled(context.Context, string, string) error
|
||||
AcceptPackageAuthority(ctx context.Context, orgID, name string, accepted Authority) (Installed, error)
|
||||
ListCatalogue(ctx context.Context) (Catalogue, error)
|
||||
InstallFromCatalogue(ctx context.Context, orgID, name string) (Installed, error)
|
||||
}
|
||||
|
||||
// Installations is Manager as a remote caller sees it: the State Store acts
|
||||
@@ -70,6 +72,8 @@ type Installations interface {
|
||||
ListInstalled(ctx context.Context) ([]Installed, error)
|
||||
RemoveInstalled(ctx context.Context, name string) error
|
||||
AcceptPackageAuthority(ctx context.Context, name string, accepted Authority) (Installed, error)
|
||||
ListCatalogue(ctx context.Context) (Catalogue, error)
|
||||
InstallFromCatalogue(ctx context.Context, name string) (Installed, error)
|
||||
}
|
||||
|
||||
// Service validates the registry content before persisting an installation.
|
||||
@@ -81,6 +85,9 @@ type Service struct {
|
||||
// and withdraws it again on removal. A family with no entry is stored but
|
||||
// never projected: installing leaves it unused until a projector lands.
|
||||
Projections map[string]FamilyProjector
|
||||
// Catalogue lists the packages an operator can install by name. Nil
|
||||
// leaves install by explicit reference and digest only.
|
||||
Catalogue CatalogueSource
|
||||
}
|
||||
|
||||
var _ Manager = Service{}
|
||||
|
||||
@@ -176,3 +176,55 @@ func authorityPtr(value *pb.PackageAuthority) *storepkg.Authority {
|
||||
authority := authorityValue(value)
|
||||
return &authority
|
||||
}
|
||||
|
||||
func (s *server) ListCatalogue(ctx context.Context, _ *pb.ListCatalogueRequest) (*pb.ListCatalogueResponse, error) {
|
||||
if s.deps.Packages == nil {
|
||||
return nil, status.Error(codes.Unavailable, "package store unavailable")
|
||||
}
|
||||
catalogue, err := s.deps.Packages.ListCatalogue(ctx)
|
||||
if err != nil {
|
||||
return nil, s.logErr("ListCatalogue", err)
|
||||
}
|
||||
out := make([]*pb.CatalogueEntry, 0, len(catalogue.Packages))
|
||||
for _, e := range catalogue.Packages {
|
||||
out = append(out, &pb.CatalogueEntry{
|
||||
Name: e.Name, Surface: e.Surface, Version: e.Version,
|
||||
Description: e.Description, Reference: e.Reference, Digest: e.Digest,
|
||||
})
|
||||
}
|
||||
return &pb.ListCatalogueResponse{Packages: out}, nil
|
||||
}
|
||||
|
||||
func (s *server) InstallFromCatalogue(ctx context.Context, request *pb.InstallFromCatalogueRequest) (*pb.InstallFromCatalogueResponse, error) {
|
||||
if s.deps.Packages == nil {
|
||||
return nil, status.Error(codes.Unavailable, "package store unavailable")
|
||||
}
|
||||
p, err := s.deps.Packages.InstallFromCatalogue(ctx, string(org.OrgFromContext(ctx)), request.GetName())
|
||||
if err != nil {
|
||||
return nil, s.logErr("InstallFromCatalogue", err)
|
||||
}
|
||||
return &pb.InstallFromCatalogueResponse{Package: packageProto(p, true)}, nil
|
||||
}
|
||||
|
||||
func (c *Client) ListCatalogue(ctx context.Context) (storepkg.Catalogue, error) {
|
||||
response, err := c.client.ListCatalogue(ctx, &pb.ListCatalogueRequest{})
|
||||
if err != nil {
|
||||
return storepkg.Catalogue{}, unmapError(err)
|
||||
}
|
||||
out := storepkg.Catalogue{Packages: make([]storepkg.CatalogueEntry, 0, len(response.GetPackages()))}
|
||||
for _, e := range response.GetPackages() {
|
||||
out.Packages = append(out.Packages, storepkg.CatalogueEntry{
|
||||
Name: e.GetName(), Surface: e.GetSurface(), Version: e.GetVersion(),
|
||||
Description: e.GetDescription(), Reference: e.GetReference(), Digest: e.GetDigest(),
|
||||
})
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *Client) InstallFromCatalogue(ctx context.Context, name string) (storepkg.Installed, error) {
|
||||
response, err := c.client.InstallFromCatalogue(ctx, &pb.InstallFromCatalogueRequest{Name: name})
|
||||
if err != nil {
|
||||
return storepkg.Installed{}, unmapError(err)
|
||||
}
|
||||
return packageValue(response.GetPackage())
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package storepkg
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/ed25519"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"oras.land/oras-go/v2/registry/remote"
|
||||
|
||||
domain "github.com/samcharles93/archie-core/internal/domain/storepkg"
|
||||
)
|
||||
|
||||
// SignatureAnnotation carries the base64 ed25519 signature over the
|
||||
// catalogue's layer bytes.
|
||||
const SignatureAnnotation = "dev.archie.catalogue.signature.v1"
|
||||
|
||||
const maxCatalogueBytes = 1 << 20
|
||||
|
||||
// DefaultCatalogue is the archipelago marketplace every instance trusts:
|
||||
// its reference, and the public half of the key that signs it.
|
||||
func DefaultCatalogue() OCICatalogue {
|
||||
return OCICatalogue{
|
||||
Reference: "ghcr.io/samcharles93/archipelago/catalogue:latest",
|
||||
Key: mustKey("YL4nvn07uq/5mXZOt9cEmLYu/kB6C2+MLTnbHyoX4Pw="),
|
||||
}
|
||||
}
|
||||
|
||||
func mustKey(encoded string) ed25519.PublicKey {
|
||||
key, err := base64.StdEncoding.DecodeString(encoded)
|
||||
if err != nil || len(key) != ed25519.PublicKeySize {
|
||||
panic("storepkg: invalid catalogue key")
|
||||
}
|
||||
return key
|
||||
}
|
||||
|
||||
// OCICatalogue fetches a catalogue artifact and verifies it against Key: a
|
||||
// one-layer OCI manifest whose layer is the catalogue JSON and whose
|
||||
// annotation signs that layer. The reference may be a tag; the signature,
|
||||
// not the tag, is what makes the list trustworthy.
|
||||
type OCICatalogue struct {
|
||||
Reference string
|
||||
Key ed25519.PublicKey
|
||||
}
|
||||
|
||||
var _ domain.CatalogueSource = OCICatalogue{}
|
||||
|
||||
func (c OCICatalogue) Fetch(ctx context.Context) (domain.Catalogue, error) {
|
||||
if len(c.Key) != ed25519.PublicKeySize {
|
||||
return domain.Catalogue{}, errors.New("catalogue: no valid signing key")
|
||||
}
|
||||
repository, err := remote.NewRepository(c.Reference)
|
||||
if err != nil {
|
||||
return domain.Catalogue{}, err
|
||||
}
|
||||
repository.PlainHTTP = loopbackReference(c.Reference)
|
||||
_, stream, err := repository.FetchReference(ctx, c.Reference)
|
||||
if err != nil {
|
||||
return domain.Catalogue{}, fmt.Errorf("catalogue: %w", err)
|
||||
}
|
||||
manifest, err := readBounded(stream, maxManifestBytes)
|
||||
if err != nil {
|
||||
return domain.Catalogue{}, err
|
||||
}
|
||||
var image ocispec.Manifest
|
||||
if err := json.Unmarshal(manifest, &image); err != nil {
|
||||
return domain.Catalogue{}, fmt.Errorf("catalogue manifest: %w", err)
|
||||
}
|
||||
if len(image.Layers) != 1 {
|
||||
return domain.Catalogue{}, errors.New("catalogue must have one layer")
|
||||
}
|
||||
layerStream, err := repository.Fetch(ctx, image.Layers[0])
|
||||
if err != nil {
|
||||
return domain.Catalogue{}, fmt.Errorf("catalogue layer: %w", err)
|
||||
}
|
||||
layer, err := readBounded(layerStream, maxCatalogueBytes)
|
||||
if err != nil {
|
||||
return domain.Catalogue{}, err
|
||||
}
|
||||
return verifyCatalogue(image, layer, c.Key)
|
||||
}
|
||||
|
||||
// verifyCatalogue checks the layer is the one the manifest names and that the
|
||||
// key signed it, then decodes it.
|
||||
func verifyCatalogue(image ocispec.Manifest, layer []byte, key ed25519.PublicKey) (domain.Catalogue, error) {
|
||||
if contentDigest(layer) != image.Layers[0].Digest.String() {
|
||||
return domain.Catalogue{}, errors.New("catalogue layer does not match its manifest digest")
|
||||
}
|
||||
signature, err := base64.StdEncoding.DecodeString(image.Annotations[SignatureAnnotation])
|
||||
if err != nil || !ed25519.Verify(key, layer, signature) {
|
||||
return domain.Catalogue{}, errors.New("catalogue signature does not verify")
|
||||
}
|
||||
decoder := json.NewDecoder(bytes.NewReader(layer))
|
||||
decoder.DisallowUnknownFields()
|
||||
var catalogue domain.Catalogue
|
||||
if err := decoder.Decode(&catalogue); err != nil {
|
||||
return domain.Catalogue{}, fmt.Errorf("catalogue: %w", err)
|
||||
}
|
||||
if err := catalogue.Validate(); err != nil {
|
||||
return domain.Catalogue{}, err
|
||||
}
|
||||
return catalogue, nil
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package storepkg
|
||||
|
||||
import (
|
||||
"crypto/ed25519"
|
||||
"encoding/base64"
|
||||
"testing"
|
||||
|
||||
digest "github.com/opencontainers/go-digest"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
)
|
||||
|
||||
// A catalogue is trusted only when its layer is the one the manifest names
|
||||
// and the configured key signed exactly those bytes.
|
||||
func TestVerifyCatalogue(t *testing.T) {
|
||||
trusted, signer, _ := ed25519.GenerateKey(nil)
|
||||
_, stranger, _ := ed25519.GenerateKey(nil)
|
||||
valid := []byte(`{"packages":[{"name":"github","reference":"ghcr.io/x/github","digest":"sha256:` + zeros + `"}]}`)
|
||||
unpinned := []byte(`{"packages":[{"name":"github","reference":"ghcr.io/x/github","digest":"latest"}]}`)
|
||||
|
||||
manifest := func(layer []byte, signature string) ocispec.Manifest {
|
||||
return ocispec.Manifest{
|
||||
Layers: []ocispec.Descriptor{{Digest: digest.FromBytes(layer)}},
|
||||
Annotations: map[string]string{SignatureAnnotation: signature},
|
||||
}
|
||||
}
|
||||
sign := func(key ed25519.PrivateKey, layer []byte) string {
|
||||
return base64.StdEncoding.EncodeToString(ed25519.Sign(key, layer))
|
||||
}
|
||||
tampered := append([]byte(nil), valid...)
|
||||
tampered[len(tampered)-3] = 'x'
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
manifest ocispec.Manifest
|
||||
layer []byte
|
||||
ok bool
|
||||
}{
|
||||
{"signed by the trusted key", manifest(valid, sign(signer, valid)), valid, true},
|
||||
{"layer swapped after signing", manifest(valid, sign(signer, valid)), tampered, false},
|
||||
{"layer and digest swapped together", manifest(tampered, sign(signer, valid)), tampered, false},
|
||||
{"signed by another key", manifest(valid, sign(stranger, valid)), valid, false},
|
||||
{"unsigned", manifest(valid, ""), valid, false},
|
||||
{"an entry without a digest pin", manifest(unpinned, sign(signer, unpinned)), unpinned, false},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
_, err := verifyCatalogue(tc.manifest, tc.layer, trusted)
|
||||
if (err == nil) != tc.ok {
|
||||
t.Errorf("%s: err = %v, want ok %v", tc.name, err, tc.ok)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const zeros = "0000000000000000000000000000000000000000000000000000000000000000"
|
||||
@@ -267,3 +267,50 @@ func (s *Server) handleExtensionRemove(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
writeJSON(w, map[string]any{"name": name, "removed": true})
|
||||
}
|
||||
|
||||
// catalogueView is one package the catalogue offers, marked when this org has
|
||||
// it installed.
|
||||
type catalogueView struct {
|
||||
storepkg.CatalogueEntry
|
||||
Installed bool `json:"installed"`
|
||||
}
|
||||
|
||||
// handleCatalogue lists the packages the verified catalogue offers.
|
||||
func (s *Server) handleCatalogue(w http.ResponseWriter, r *http.Request) {
|
||||
if !s.extensionsReady(w) {
|
||||
return
|
||||
}
|
||||
catalogue, err := s.Packages.ListCatalogue(r.Context())
|
||||
if err != nil {
|
||||
http.Error(w, "catalogue unavailable: "+err.Error(), http.StatusBadGateway)
|
||||
return
|
||||
}
|
||||
installed, err := s.Packages.ListInstalled(r.Context())
|
||||
if err != nil {
|
||||
writePackageError(w, err)
|
||||
return
|
||||
}
|
||||
have := make(map[string]bool, len(installed))
|
||||
for _, p := range installed {
|
||||
have[p.Name] = true
|
||||
}
|
||||
out := make([]catalogueView, 0, len(catalogue.Packages))
|
||||
for _, entry := range catalogue.Packages {
|
||||
out = append(out, catalogueView{CatalogueEntry: entry, Installed: have[entry.Name]})
|
||||
}
|
||||
writeJSON(w, out)
|
||||
}
|
||||
|
||||
// handleCatalogueInstall installs one catalogue package by name, at the digest
|
||||
// the verified catalogue pins.
|
||||
func (s *Server) handleCatalogueInstall(w http.ResponseWriter, r *http.Request) {
|
||||
if !s.extensionsReady(w) {
|
||||
return
|
||||
}
|
||||
p, err := s.Packages.InstallFromCatalogue(r.Context(), r.PathValue("name"))
|
||||
if err != nil {
|
||||
writePackageError(w, err)
|
||||
return
|
||||
}
|
||||
writeJSON(w, extensionView(p, false))
|
||||
}
|
||||
@@ -317,6 +317,8 @@ func (s *Server) registerHarnessRoutes(mux *http.ServeMux) {
|
||||
func (s *Server) registerConfigAndLogRoutes(mux *http.ServeMux) {
|
||||
mux.HandleFunc("GET /api/extensions", s.handleExtensions)
|
||||
mux.HandleFunc("POST /api/extensions", s.handleExtensionInstall)
|
||||
mux.HandleFunc("GET /api/extensions/catalogue", s.handleCatalogue)
|
||||
mux.HandleFunc("POST /api/extensions/catalogue/{name}/install", s.handleCatalogueInstall)
|
||||
mux.HandleFunc("POST /api/extensions/{name}/accept", s.handleExtensionAccept)
|
||||
mux.HandleFunc("PUT /api/extensions/{name}/enabled", s.handleExtensionEnabled)
|
||||
mux.HandleFunc("DELETE /api/extensions/{name}", s.handleExtensionRemove)
|
||||
|
||||
Reference in new issue
Block a user