Skip to content

propose approach and syntax for "sugary" content digests #194

Closed

Description

@stevvooe

While the digests provide a lot of benefits, they are long and unwieldy for users. To mitigate this, we should propose a syntax for shortening identifiers, much in the way git does. It should meet at least the following requirements:

  • Resolves content uniquely with a low probability of collision
  • Shortened digests should not leak into persistent systems
  • The solution should not compromise security

This was request in moby/moby#10740 (comment).

Activity

  1. added this to the milestone on Feb 20, 2015
  2. dmcgowan commented on Feb 20, 2015

    @dmcgowan
    Collaborator

    My only concern from a security end is that using a shortened identifier will then require a trust check. Which means the shortened identifier needs to be registered with the trust system. The vulnerability being that at some point the shortened identifier needs to be resolved to a full hash. If it is simply trusting the registry to provide the full hash, then the operation is no longer trusted. Yes git may allow using shortened IDs, but that is under the assumption the client has the full view of the repository and therefore able to detect ID collisions for itself.

  3. dmcgowan commented on Feb 20, 2015

    @dmcgowan
    Collaborator

    A possible solution may be for the client to download a taglist, which will require a trust check. Once the client has the tag list, it would then be able to expand the identifier for itself. If that is the best solution, then this is a client side operation, possibly we should just provide a trusted list of hashes + utility for resolving.

  4. stevvooe commented on Mar 11, 2015

    @stevvooe
    CollaboratorAuthor

    @dmcgowan Should all sets of digest be concrete, in-memory to enforce some notion of transformation?

    Something like this would be a mutable implementation:

    type Digests digestEntries
    
    func (ds Digests) Lookup(short string) Digest {
        // use http://golang.org/pkg/sort/#Search to find prefix
    }
    
    func (ds Digests) Add(d Digest) error {
        // insort the digest using http://golang.org/pkg/sort/#Search
        // slightly expensive memory wise, maybe.
    }
    
    type digestEntry struct {
        alg string
        digest string
    }
    
    type digestEntries []digestEntry
    
    // sort methods
    func (d digestEntries) Len() int {}
    func (d digestEntries) Less(i, j int) bool
    func (d digestEntries) Swap(i, j int)
    

    An immutable implementation would be something like this, using suffix array:

        // Note that we have record markers on either end to make finding complete
        // record easier.
        data := []byte("\nsha256:asdfasdfasdfasdfasdf\nsha256:qwerqwerqwerqwer\nsha256:01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b\n")
        index := suffixarray.New(data)
        short := os.Args[1]
    
        // If an algorithem is not specified, affix the query to the colon
        if !strings.Contains(short, ":") {
            short = ":" + short
        }
    
        results := index.Lookup([]byte(short), 2)
    
        if len(results) > 1 {
            fmt.Println("short hash not unique")
            os.Exit(1)
        }
    
        for _, result := range results {
            start := bytes.LastIndex(data[:result], []byte("\n"))
            end := bytes.Index(data[result:], []byte("\n")) + result
            record := data[start+1 : end]
            fmt.Println(string(record))
        }
    
  5. dmcgowan commented on Mar 11, 2015

    @dmcgowan
    Collaborator

    I like the first section, the only function I would add is to get a map of Digest to short code

    func (ds Digests) ShortMap(length int) map[Digest]string {
        // Provides unique short codes for each digest with minimum of length
        // If two digests have the same prefix of minimum length, the minimum
        // unique prefix will be returned, which may be the entire digest string
    }
    
  6. modified the milestones: , Registry/2.0, Registry/2.1 on Mar 31, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions