Use UUIDv4 not UUIDv1

UUIDv1 has several disadvantages:
 - it encodes the MAC address of the host, which is a potential privacy issue
 - it uses the clock of the host, which reveals time information
 - the clock is very coarse, hence the complex code handling duplicates

UUIDv4 is simply a 122 bit random number encoded into the UUID format, which
has no problems with duplicates or locking.

Use the google/uuid library, as newer versions of pborman/uuid just wrap the
Google upstream.

Note that technically a random UUID might fail, but Go ensures that this
should not take place, as it will block if entropy is not available.

Signed-off-by: Justin Cormack <justin.cormack@docker.com>
This commit is contained in:
Justin Cormack 2019-03-11 20:30:20 +00:00
parent 6ec5a7d337
commit 0fb4b81c3f
No known key found for this signature in database
GPG Key ID: 609102888A2EE3F9
7 changed files with 23 additions and 23 deletions

View File

@ -470,6 +470,10 @@
"ImportPath": "github.com/google/gofuzz",
"Rev": "24818f796faf91cd76ec7bddd72458fbced7a6c1"
},
{
"ImportPath": "github.com/google/uuid",
"Rev": "8c31c18f31ede9fc8eae72290a7e7a8064e9b3e3"
},
{
"ImportPath": "github.com/googleapis/gnostic/OpenAPIv2",
"Rev": "0c5108395e2debce0d731cf0287ddf7242066aba"

View File

@ -62,6 +62,10 @@
"ImportPath": "github.com/google/gofuzz",
"Rev": "24818f796faf91cd76ec7bddd72458fbced7a6c1"
},
{
"ImportPath": "github.com/google/uuid",
"Rev": "8c31c18f31ede9fc8eae72290a7e7a8064e9b3e3"
},
{
"ImportPath": "github.com/googleapis/gnostic/OpenAPIv2",
"Rev": "0c5108395e2debce0d731cf0287ddf7242066aba"
@ -98,10 +102,6 @@
"ImportPath": "github.com/mxk/go-flowrate/flowrate",
"Rev": "cca7078d478f8520f85629ad7c68962d31ed7682"
},
{
"ImportPath": "github.com/pborman/uuid",
"Rev": "ca53cad383cad2479bbba7f7a1a05797ec1386e4"
},
{
"ImportPath": "github.com/pmezard/go-difflib/difflib",
"Rev": "5d4384ee4fb2527b0a1256a821ebfc92f91efefc"

View File

@ -12,7 +12,7 @@ go_library(
importpath = "k8s.io/apimachinery/pkg/util/uuid",
deps = [
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
"//vendor/github.com/pborman/uuid:go_default_library",
"//vendor/github.com/google/uuid:go_default_library",
],
)

View File

@ -17,27 +17,11 @@ limitations under the License.
package uuid
import (
"sync"
"github.com/pborman/uuid"
"github.com/google/uuid"
"k8s.io/apimachinery/pkg/types"
)
var uuidLock sync.Mutex
var lastUUID uuid.UUID
func NewUUID() types.UID {
uuidLock.Lock()
defer uuidLock.Unlock()
result := uuid.NewUUID()
// The UUID package is naive and can generate identical UUIDs if the
// time interval is quick enough.
// The UUID uses 100 ns increments so it's short enough to actively
// wait for a new value.
for uuid.Equal(lastUUID, result) == true {
result = uuid.NewUUID()
}
lastUUID = result
return types.UID(result.String())
return types.UID(uuid.New().String())
}

View File

@ -450,6 +450,10 @@
"ImportPath": "github.com/google/gofuzz",
"Rev": "24818f796faf91cd76ec7bddd72458fbced7a6c1"
},
{
"ImportPath": "github.com/google/uuid",
"Rev": "8c31c18f31ede9fc8eae72290a7e7a8064e9b3e3"
},
{
"ImportPath": "github.com/googleapis/gnostic/OpenAPIv2",
"Rev": "0c5108395e2debce0d731cf0287ddf7242066aba"

View File

@ -142,6 +142,10 @@
"ImportPath": "github.com/google/gofuzz",
"Rev": "24818f796faf91cd76ec7bddd72458fbced7a6c1"
},
{
"ImportPath": "github.com/google/uuid",
"Rev": "8c31c18f31ede9fc8eae72290a7e7a8064e9b3e3"
},
{
"ImportPath": "github.com/googleapis/gnostic/OpenAPIv2",
"Rev": "0c5108395e2debce0d731cf0287ddf7242066aba"

View File

@ -134,6 +134,10 @@
"ImportPath": "github.com/google/gofuzz",
"Rev": "24818f796faf91cd76ec7bddd72458fbced7a6c1"
},
{
"ImportPath": "github.com/google/uuid",
"Rev": "8c31c18f31ede9fc8eae72290a7e7a8064e9b3e3"
},
{
"ImportPath": "github.com/googleapis/gnostic/OpenAPIv2",
"Rev": "0c5108395e2debce0d731cf0287ddf7242066aba"