Skip to content

Commit 0fb4b81

Browse files
committed
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 <[email protected]>
1 parent 6ec5a7d commit 0fb4b81

File tree

7 files changed

+23
-23
lines changed

7 files changed

+23
-23
lines changed

staging/src/k8s.io/apiextensions-apiserver/Godeps/Godeps.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/apimachinery/Godeps/Godeps.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/apimachinery/pkg/util/uuid/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ go_library(
1212
importpath = "k8s.io/apimachinery/pkg/util/uuid",
1313
deps = [
1414
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
15-
"//vendor/github.com/pborman/uuid:go_default_library",
15+
"//vendor/github.com/google/uuid:go_default_library",
1616
],
1717
)
1818

staging/src/k8s.io/apimachinery/pkg/util/uuid/uuid.go

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,11 @@ limitations under the License.
1717
package uuid
1818

1919
import (
20-
"sync"
21-
22-
"github.com/pborman/uuid"
20+
"github.com/google/uuid"
2321

2422
"k8s.io/apimachinery/pkg/types"
2523
)
2624

27-
var uuidLock sync.Mutex
28-
var lastUUID uuid.UUID
29-
3025
func NewUUID() types.UID {
31-
uuidLock.Lock()
32-
defer uuidLock.Unlock()
33-
result := uuid.NewUUID()
34-
// The UUID package is naive and can generate identical UUIDs if the
35-
// time interval is quick enough.
36-
// The UUID uses 100 ns increments so it's short enough to actively
37-
// wait for a new value.
38-
for uuid.Equal(lastUUID, result) == true {
39-
result = uuid.NewUUID()
40-
}
41-
lastUUID = result
42-
return types.UID(result.String())
26+
return types.UID(uuid.New().String())
4327
}

staging/src/k8s.io/apiserver/Godeps/Godeps.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/kube-aggregator/Godeps/Godeps.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/sample-apiserver/Godeps/Godeps.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)