Documentation ¶
Index ¶
- Constants
- Variables
- func AddKeys(recipientPubKeyPaths []string, envelope *Envelope, plainKey []byte) error
- func BytesToTar(w *tar.Writer, filename *string, contents []byte) error
- func CleanupFileWriter(output string, f *os.File) error
- func CleanupImages() error
- func CreatePKISigner(pkeyPath string) (signature.Signer, error)
- func CreatePKIVerifier(skeyPath string) (signature.Verifier, error)
- func CreateSigner(privateKeyPath string) (signature.Signer, error)
- func Encrypt(unencrypted []byte) ([]byte, []byte, error)
- func EncryptWriter(w io.Writer) (string, io.WriteCloser)
- func GetCompressionAlgoIndex(algo string) uint8
- func GetCompressionAlgoName(idx uint8) string
- func GetContainerDSocket() (string, error)
- func GetHashAlgorithm(algo string) crypto.Hash
- func ImportImage(namespace, targetRegistry string, tarReader io.ReadCloser, tag *name.Tag) (newImport bool, err error)
- func LoadPrivateKey(path string) (interface{}, error)
- func LoadPublicKey(path string) (crypto.PublicKey, error)
- func NewOutputFile(output string) (*os.File, error)
- func ReadConfiguration(fileName string, files *[]string, images *[]*ContainerImage) error
- func RemoveAll(namespace, targetRegistry string, tags []*name.Tag) (err error)
- func SaveImage(img *ContainerImage) (result *os.File, err error)
- func TryUnsealKey(encrypted []byte, rsaKey *rsa.PrivateKey) (symmecrypt.Key, error)
- func WriteFileBytes(output string, contents []byte) error
- type ArchiveContents
- type ContainerImage
- type Descriptor
- type Envelope
- func (e *Envelope) GetPayload(privateKeyPath string) (payload io.Reader, err error)
- func (e *Envelope) String() string
- func (e *Envelope) ToBytes() []byte
- func (e *Envelope) WriteHeader(w io.Writer) error
- func (e *Envelope) WriteKeys(w io.Writer) error
- func (e *Envelope) WriteOutput(f *os.File, arc *WriteArchive) error
- type FileSignatures
- func (f *FileSignatures) AddFile(name string, contents []byte) error
- func (f *FileSignatures) AddFileFromReader(name string, contents io.Reader) (err error)
- func (f *FileSignatures) Bytes() []byte
- func (f *FileSignatures) Equals(other *FileSignatures) bool
- func (f *FileSignatures) Save(name string) error
- type ImageContent
- type Manifest
- type OutManifest
- type PackageContent
- type ReadArchive
- type Signer
- type Verifier
- type WriteArchive
- func (arc *WriteArchive) AddContents(files []string, images []*ContainerImage, signatures *FileSignatures) (err error)
- func (arc *WriteArchive) AddToArchive(imgName string, contents []byte) error
- func (arc *WriteArchive) AddToc(privateKeyPath string, signatures *FileSignatures) (err error)
- func (arc *WriteArchive) Cleanup() error
- func (arc *WriteArchive) Finalize() (int64, error)
- func (arc *WriteArchive) InitializeCompression(w io.WriteCloser, compressionAlgo uint8)
- func (arc *WriteArchive) WriteToArchive(fileName string, contents *os.File) error
Constants ¶
const ( // EnvelopeMagicBytes is set to ASCII sum of "ECS" = 333(octal) or DB(hex) EnvelopeMagicBytes = "\xDBIPC" TocFileName = ".sealpack.toc" )
const ( CompressionGzip = "gzip" CompressionZlib = "zlib" CompressionZip = "zip" CompressionFlate = "flate" )
const ( TmpFolderName = "crane.dl" ContainerDSocketFolder = "/run" ContainerDSocketFile = "containerd.sock" LocalContainerRegistry = "local" )
const ( ContainerImagePrefix = ".images" OCISuffix = ".oci" )
const (
DefaultRegistry = "docker.io"
)
const Delimiter = ":"
Delimiter delimits the file name from its hash
Variables ¶
var (
ContainerDSocket = ""
)
Functions ¶
func AddKeys ¶
AddKeys encrypts the symmetric key for every receiver and attaches them to the envelope
func BytesToTar ¶
BytesToTar adds a file to a writer using a filename and a byte slice with contents to be written.
func CleanupFileWriter ¶
CleanupFileWriter cleans up temporary files and performs post-finish operations
func CleanupImages ¶
func CleanupImages() error
CleanupImages removes the temp folder where container images are stored.
func CreatePKISigner ¶
CreatePKISigner uses the private key to create a signature.Signer instance
func CreatePKIVerifier ¶
CreatePKIVerifier builds a verifier based on a public key
func CreateSigner ¶
CreateSigner cheese the correct signature.Signer depending on the private key string
func Encrypt ¶
Encrypt the contents of an os.File with a random key and retrieve the results as []byte The asymmetrically encrypted encryption key is attached als the last [ KeySizeBit ] bytes
func EncryptWriter ¶
func EncryptWriter(w io.Writer) (string, io.WriteCloser)
func GetCompressionAlgoIndex ¶
GetCompressionAlgoIndex gets the index of an algo name or defaults to 0 (gzip)
func GetCompressionAlgoName ¶
GetCompressionAlgoName gets the name of an algo index or defaults to gzip (0)
func GetContainerDSocket ¶
GetContainerDSocket searched for a containerD socket in the /run folder
func GetHashAlgorithm ¶
GetHashAlgorithm retrieves a crypto.Hash for a name. if no available name is provided, SHA512 is returned.
func ImportImage ¶
func ImportImage(namespace, targetRegistry string, tarReader io.ReadCloser, tag *name.Tag) (newImport bool, err error)
ImportImage imports one OCI image into a local containerd storage or a provided registry.
func LoadPrivateKey ¶
LoadPrivateKey reads and parses a private key from a file
func LoadPublicKey ¶
LoadPublicKey reads and parses a public key from a file
func NewOutputFile ¶
NewOutputFile creates a new output file depending on the type of output target
func ReadConfiguration ¶
func ReadConfiguration(fileName string, files *[]string, images *[]*ContainerImage) error
ReadConfiguration searches for the latest configuration file and reads the contents. The contents are parsed as a slice of PackageContent from a JSON or YAML file.
func SaveImage ¶
func SaveImage(img *ContainerImage) (result *os.File, err error)
SaveImage with from a registry to a local OCI file.
func TryUnsealKey ¶
func TryUnsealKey(encrypted []byte, rsaKey *rsa.PrivateKey) (symmecrypt.Key, error)
TryUnsealKey loads a key from JSON without configstore
func WriteFileBytes ¶
WriteFileBytes allows for writing a byte slice to a regular file, S3 bucket or stdout
Types ¶
type ArchiveContents ¶
ArchiveContents describes all contents for an archive to provide them as a single file.
type ContainerImage ¶
type ContainerImage struct { Registry string `json:"registry"` Name string `json:"name"` Tag string `json:"tag"` }
ContainerImage describes a container image uniquely
func ParseContainerImage ¶
func ParseContainerImage(name string) *ContainerImage
ParseContainerImage takes a string describing an image and parses the registry, name and tag out of it.
func (*ContainerImage) String ¶
func (i *ContainerImage) String() string
String creates the image URI form the parts.
func (*ContainerImage) ToFileName ¶
func (i *ContainerImage) ToFileName() string
ToFileName creates a file name to store the image archive in.
type Descriptor ¶
Descriptor is a standard OCI descriptor. For easier handling, this implementation only contains the necessary properties. @url https://github.com/opencontainers/image-spec/blob/main/descriptor.md
type Envelope ¶
type Envelope struct { PayloadLen int64 PayloadReader io.ReadSeeker PayloadWriter *os.File HashAlgorithm crypto.Hash CompressionAlgo uint8 ReceiverKeys [][]byte }
Envelope is the package with headers and so on
func ParseEnvelope ¶
func ParseEnvelope(input io.ReadSeeker) (*Envelope, error)
ParseEnvelope tries to extract the information for an Envelope from a byte slice
func (*Envelope) GetPayload ¶
GetPayload provides the Payload from the envelope
func (*Envelope) String ¶
String prints a string representation of an Envelope with basic information
func (*Envelope) ToBytes ¶
ToBytes provides an Envelope as Bytes. Caution: using this method may massively increase memory usage!
func (*Envelope) WriteHeader ¶
WriteHeader writes the envelope headers to an io.Writer.
func (*Envelope) WriteOutput ¶
func (e *Envelope) WriteOutput(f *os.File, arc *WriteArchive) error
WriteOutput creates an encrypted output file from encrypted payload
type FileSignatures ¶
A FileSignatures is represented by its path and the hash of the file
func NewSignatureList ¶
func NewSignatureList(algo string) *FileSignatures
NewSignatureList creates a new signature list
func (*FileSignatures) AddFile ¶
func (f *FileSignatures) AddFile(name string, contents []byte) error
AddFile hashes a file and its contents and adds it to the list
func (*FileSignatures) AddFileFromReader ¶
func (f *FileSignatures) AddFileFromReader(name string, contents io.Reader) (err error)
AddFileFromReader hashes a file and its contents and adds it to the list
func (*FileSignatures) Bytes ¶
func (f *FileSignatures) Bytes() []byte
Bytes gets the list formatted as []byte
func (*FileSignatures) Equals ¶
func (f *FileSignatures) Equals(other *FileSignatures) bool
Equals compares 2 FileSignatures for equality
func (*FileSignatures) Save ¶
func (f *FileSignatures) Save(name string) error
Save the signatures list to a file
type ImageContent ¶
type ImageContent struct { Name string `json:"name"` Tag string `json:"tag"` Registry string `json:"registry"` IsImage bool `json:"is_image"` }
ImageContent represents one component to be included in the upgrade package. If IsImage is set true, the component will be pulled by Name and Tag from the ECR registry. If only name is provided, a static file is expected.
type Manifest ¶
type Manifest struct { SchemaVersion int Config Descriptor Layers []Descriptor Annotations map[string]string }
Manifest represents an OCI image manifest, typically provided as json. For easier handling, this implementation only contains the necessary properties. @url https://github.com/opencontainers/image-spec/blob/main/manifest.md
type OutManifest ¶
type OutManifest struct { Config string `json:"Config"` RepoTags []string `json:"RepoTags"` Layers []string `json:"Layers"` }
OutManifest is the manifest in docker (moby) image format. For easier handling, this implementation only contains the necessary properties. @url https://github.com/moby/moby/blob/master/image/tarexport/tarexport.go#L18-L24
type PackageContent ¶
type PackageContent interface {
PackagePath() string
}
type ReadArchive ¶
func OpenArchive ¶
func OpenArchive(data []byte, compressionAlgo uint8) (arc *ReadArchive, err error)
OpenArchive opens a compressed tar archive for reading
func OpenArchiveReader ¶
func OpenArchiveReader(r io.Reader, compressionAlgo uint8) (arc *ReadArchive, err error)
OpenArchiveReader opens a compressed tar archive for reading from a reader
func (*ReadArchive) InitializeCompression ¶
func (arc *ReadArchive) InitializeCompression(r io.Reader, compressionAlgo uint8) (err error)
InitializeCompression creates a compression writer based on selected algorithm
func (*ReadArchive) Unpack ¶
func (arc *ReadArchive) Unpack(signingKeyPath, hashingAlgorithm, outputPath, namespace, targetRegistry string) (err error)
type Signer ¶
type Signer struct {
Signer *signature.SignerVerifier
}
type Verifier ¶
type Verifier struct { Signatures *FileSignatures // contains filtered or unexported fields }
Verifier contains all data necessary to verify the archive's integrity
func NewVerifier ¶
NewVerifier Creates a new sealpack integrity verifier structure
func (*Verifier) AddTocComponent ¶
AddTocComponent adds a TOC or TOC-Signature from a tar reader
func (*Verifier) AddUnsafeTag ¶
AddUnsafeTag adds an unsafe tag to the list
type WriteArchive ¶
type WriteArchive struct { EncryptionKey string // contains filtered or unexported fields }
func CreateArchiveWriter ¶
func CreateArchiveWriter(public bool, compressionAlgo uint8) *WriteArchive
CreateArchiveWriter opens a stream of writers (tar to gzip to buffer) and funnel to a csutom writer.
func (*WriteArchive) AddContents ¶
func (arc *WriteArchive) AddContents(files []string, images []*ContainerImage, signatures *FileSignatures) (err error)
AddContents adds first files, secondly images to the WriteArchive providing FileSignatures for verification
func (*WriteArchive) AddToArchive ¶
func (arc *WriteArchive) AddToArchive(imgName string, contents []byte) error
AddToArchive adds a new file identified by its name to the tar.gz archive. The contents are added as byte slices.
func (*WriteArchive) AddToc ¶
func (arc *WriteArchive) AddToc(privateKeyPath string, signatures *FileSignatures) (err error)
AddToc adds signatures to the archive
func (*WriteArchive) Cleanup ¶
func (arc *WriteArchive) Cleanup() error
Cleanup closes streams and removes temporary files
func (*WriteArchive) Finalize ¶
func (arc *WriteArchive) Finalize() (int64, error)
Finalize closes the tar and gzip writers and retrieves the archive. Additionally, it returns the size of the payload.
func (*WriteArchive) InitializeCompression ¶
func (arc *WriteArchive) InitializeCompression(w io.WriteCloser, compressionAlgo uint8)
InitializeCompression creates a compression writer based on selected algorithm
func (*WriteArchive) WriteToArchive ¶
func (arc *WriteArchive) WriteToArchive(fileName string, contents *os.File) error
WriteToArchive adds a new file identified by its name to the tar.gz archive. The contents are added as reader resource.